From c49766f42955755a22ca25bed5eed35719f046b4 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Fri, 6 Sep 2024 09:38:54 +0200 Subject: [PATCH] refactor --- .env | 4 +- .github/workflows/nodejs.yml | 10 +- {contracts => contracts-c}/auction/auction.c | 0 .../auction/auction_start.c | 0 .../autotransfer/autotransfer.c | 0 .../checkout/checkout.c | 0 {contracts => contracts-c}/did/did.c | 0 .../highvalue/highvalue_block.c | 0 .../highvalue/highvalue_prepare.c | 0 {contracts => contracts-c}/loan/admin.c | 0 {contracts => contracts-c}/loan/loan.c | 0 {contracts => contracts-c}/loan/p2p_loan.c | 0 {contracts => contracts-c}/loan/pool.c | 0 {contracts => contracts-c}/lottery/lottery.c | 0 .../lottery/lottery_end.c | 0 .../lottery/lottery_end_ic.c | 0 .../lottery/lottery_ic.c | 0 .../lottery/lottery_start.c | 0 {contracts => contracts-c}/oracle/oracle.c | 0 .../portfolio/trailing_stop.c | 0 .../redirect/redirect.c | 0 .../router/router_base.c | 0 .../router/router_check_1.c | 0 .../router/router_check_2.c | 0 .../router/router_check_3.c | 0 {contracts => contracts-c}/utils/date.h | 0 {contracts => contracts-c}/utils/error.h | 0 {contracts => contracts-c}/utils/extern.h | 0 {contracts => contracts-c}/utils/hookapi.h | 0 {contracts => contracts-c}/utils/macro.h | 0 {contracts => contracts-c}/utils/sfcodes.h | 0 .../voucher/voucher_claim.c | 0 .../voucher/voucher_create.c | 0 .../@types/global.d.ts | 0 .../oracle/oracle.ts | 0 contracts/funds/modular/master.c | 658 -------------- contracts/funds/modular/user.c | 743 ---------------- contracts/funds/monolithic/monolithic.c | 836 ------------------ ...gration.js => jest.config.integration-c.js | 2 +- jest.config.integration-js.js | 9 + package.json | 9 +- .../auction/README.md | 0 .../auction/auction.test.ts | 0 .../auction/auctionStart.test.ts | 0 .../auction/models/AuctionModel.ts | 0 .../autotransfer/README.md | 0 .../autotransfer/autotransfer.test.ts | 0 .../checkout/README.md | 0 .../checkout/checkout.test.ts | 0 .../checkout/models/SellerArray.ts | 0 .../checkout/models/SellerModel.ts | 0 .../did/did.test.ts | 0 .../did/models/DIDModel.ts | 0 .../highvalue/highvalueBlock.test.ts | 0 .../highvalue/highvaluePrepare.test.ts | 0 .../loan/README.md | 0 .../loan/admin.test.ts | 0 .../loan/loanPool.test.ts | 1 + .../loan/models/Loan.ts | 0 .../loan/models/Pool.ts | 0 .../loan/models/utils/AmountModel.ts | 0 .../loan/models/utils/IssueModel.ts | 0 .../loan/pool.test.ts | 0 .../loan/utils.ts | 0 .../lottery/README.md | 0 .../lottery/lottery.test.ts | 0 .../lottery/models/LotteryModel.ts | 0 .../oracle/models/OracleArrayModel.ts | 0 .../oracle/models/OracleModel.ts | 0 .../oracle/oracle.js.test.ts | 0 .../oracle/oracle.test.ts | 0 .../portfolio/portfolio.test.ts | 0 .../portfolio/utils.ts | 0 .../redirect/redirect.test.ts | 0 .../router/README.md | 0 .../router/models/HookPosArray.ts | 0 .../router/models/HookPosModel.ts | 0 .../router/router.test.ts | 0 .../voucher/models/VoucherModel.ts | 0 .../voucher/voucher.test.ts | 0 .../oracle/models/OracleArrayModel.ts | 31 + .../oracle/models/OracleModel.ts | 41 + test/integration-js/oracle/oracle.js.test.ts | 108 +++ test/integration/funds/modular.test.ts | 810 ----------------- test/integration/funds/monolithic.test.ts | 556 ------------ yarn.lock | 159 +++- 86 files changed, 361 insertions(+), 3616 deletions(-) rename {contracts => contracts-c}/auction/auction.c (100%) rename {contracts => contracts-c}/auction/auction_start.c (100%) rename {contracts => contracts-c}/autotransfer/autotransfer.c (100%) rename {contracts => contracts-c}/checkout/checkout.c (100%) rename {contracts => contracts-c}/did/did.c (100%) rename {contracts => contracts-c}/highvalue/highvalue_block.c (100%) rename {contracts => contracts-c}/highvalue/highvalue_prepare.c (100%) rename {contracts => contracts-c}/loan/admin.c (100%) rename {contracts => contracts-c}/loan/loan.c (100%) rename {contracts => contracts-c}/loan/p2p_loan.c (100%) rename {contracts => contracts-c}/loan/pool.c (100%) rename {contracts => contracts-c}/lottery/lottery.c (100%) rename {contracts => contracts-c}/lottery/lottery_end.c (100%) rename {contracts => contracts-c}/lottery/lottery_end_ic.c (100%) rename {contracts => contracts-c}/lottery/lottery_ic.c (100%) rename {contracts => contracts-c}/lottery/lottery_start.c (100%) rename {contracts => contracts-c}/oracle/oracle.c (100%) rename {contracts => contracts-c}/portfolio/trailing_stop.c (100%) rename {contracts => contracts-c}/redirect/redirect.c (100%) rename {contracts => contracts-c}/router/router_base.c (100%) rename {contracts => contracts-c}/router/router_check_1.c (100%) rename {contracts => contracts-c}/router/router_check_2.c (100%) rename {contracts => contracts-c}/router/router_check_3.c (100%) rename {contracts => contracts-c}/utils/date.h (100%) rename {contracts => contracts-c}/utils/error.h (100%) rename {contracts => contracts-c}/utils/extern.h (100%) rename {contracts => contracts-c}/utils/hookapi.h (100%) rename {contracts => contracts-c}/utils/macro.h (100%) rename {contracts => contracts-c}/utils/sfcodes.h (100%) rename {contracts => contracts-c}/voucher/voucher_claim.c (100%) rename {contracts => contracts-c}/voucher/voucher_create.c (100%) rename {contractsjs => contracts-js}/@types/global.d.ts (100%) rename {contractsjs => contracts-js}/oracle/oracle.ts (100%) delete mode 100644 contracts/funds/modular/master.c delete mode 100644 contracts/funds/modular/user.c delete mode 100644 contracts/funds/monolithic/monolithic.c rename jest.config.integration.js => jest.config.integration-c.js (80%) create mode 100644 jest.config.integration-js.js rename test/{integration => integration-c}/auction/README.md (100%) rename test/{integration => integration-c}/auction/auction.test.ts (100%) rename test/{integration => integration-c}/auction/auctionStart.test.ts (100%) rename test/{integration => integration-c}/auction/models/AuctionModel.ts (100%) rename test/{integration => integration-c}/autotransfer/README.md (100%) rename test/{integration => integration-c}/autotransfer/autotransfer.test.ts (100%) rename test/{integration => integration-c}/checkout/README.md (100%) rename test/{integration => integration-c}/checkout/checkout.test.ts (100%) rename test/{integration => integration-c}/checkout/models/SellerArray.ts (100%) rename test/{integration => integration-c}/checkout/models/SellerModel.ts (100%) rename test/{integration => integration-c}/did/did.test.ts (100%) rename test/{integration => integration-c}/did/models/DIDModel.ts (100%) rename test/{integration => integration-c}/highvalue/highvalueBlock.test.ts (100%) rename test/{integration => integration-c}/highvalue/highvaluePrepare.test.ts (100%) rename test/{integration => integration-c}/loan/README.md (100%) rename test/{integration => integration-c}/loan/admin.test.ts (100%) rename test/{integration => integration-c}/loan/loanPool.test.ts (99%) rename test/{integration => integration-c}/loan/models/Loan.ts (100%) rename test/{integration => integration-c}/loan/models/Pool.ts (100%) rename test/{integration => integration-c}/loan/models/utils/AmountModel.ts (100%) rename test/{integration => integration-c}/loan/models/utils/IssueModel.ts (100%) rename test/{integration => integration-c}/loan/pool.test.ts (100%) rename test/{integration => integration-c}/loan/utils.ts (100%) rename test/{integration => integration-c}/lottery/README.md (100%) rename test/{integration => integration-c}/lottery/lottery.test.ts (100%) rename test/{integration => integration-c}/lottery/models/LotteryModel.ts (100%) rename test/{integration => integration-c}/oracle/models/OracleArrayModel.ts (100%) rename test/{integration => integration-c}/oracle/models/OracleModel.ts (100%) rename test/{integration => integration-c}/oracle/oracle.js.test.ts (100%) rename test/{integration => integration-c}/oracle/oracle.test.ts (100%) rename test/{integration => integration-c}/portfolio/portfolio.test.ts (100%) rename test/{integration => integration-c}/portfolio/utils.ts (100%) rename test/{integration => integration-c}/redirect/redirect.test.ts (100%) rename test/{integration => integration-c}/router/README.md (100%) rename test/{integration => integration-c}/router/models/HookPosArray.ts (100%) rename test/{integration => integration-c}/router/models/HookPosModel.ts (100%) rename test/{integration => integration-c}/router/router.test.ts (100%) rename test/{integration => integration-c}/voucher/models/VoucherModel.ts (100%) rename test/{integration => integration-c}/voucher/voucher.test.ts (100%) create mode 100644 test/integration-js/oracle/models/OracleArrayModel.ts create mode 100644 test/integration-js/oracle/models/OracleModel.ts create mode 100644 test/integration-js/oracle/oracle.js.test.ts delete mode 100644 test/integration/funds/modular.test.ts delete mode 100644 test/integration/funds/monolithic.test.ts diff --git a/.env b/.env index d95f35f..0ea8211 100644 --- a/.env +++ b/.env @@ -1,4 +1,2 @@ -C2WASM_CLI_HOST=https://hook-buildbox.xrpl.org -JS2WASM_CLI_HOST=https://hook-buildbox.xrpl.org -# C2WASM_CLI_HOST=http://0.0.0.0:9000 +HOOKS_COMPILE_HOST=https://hook-buildbox.xrpl.org XRPLD_ENV=standalone diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index cd14083..ffb8b7c 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -77,7 +77,7 @@ jobs: - name: Run docker in background run: | - docker run --detach --rm --name rippled-service -p 6006:6006 --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s transia/xahau-2024125-release738-xahau + docker run --detach --rm --name rippled-service -p 6006:6006 --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s transia/xahaudjs:latest - name: Setup npm version 7 run: | @@ -102,11 +102,11 @@ jobs: if: steps.cache-nodemodules.outputs.cache-hit != 'true' run: yarn install - - run: yarn run build:hooks - - run: yarn run test:integration + - run: yarn run build:hooks-c + - run: yarn run test:integration-c env: - C2WASM_CLI_HOST: https://hook-buildbox.xrpl.org - RIPPLED_ENV: standalone + HOOKS_COMPILE_HOST: https://hook-buildbox.xrpl.org + XRPLD_ENV: standalone - name: Stop docker container if: always() diff --git a/contracts/auction/auction.c b/contracts-c/auction/auction.c similarity index 100% rename from contracts/auction/auction.c rename to contracts-c/auction/auction.c diff --git a/contracts/auction/auction_start.c b/contracts-c/auction/auction_start.c similarity index 100% rename from contracts/auction/auction_start.c rename to contracts-c/auction/auction_start.c diff --git a/contracts/autotransfer/autotransfer.c b/contracts-c/autotransfer/autotransfer.c similarity index 100% rename from contracts/autotransfer/autotransfer.c rename to contracts-c/autotransfer/autotransfer.c diff --git a/contracts/checkout/checkout.c b/contracts-c/checkout/checkout.c similarity index 100% rename from contracts/checkout/checkout.c rename to contracts-c/checkout/checkout.c diff --git a/contracts/did/did.c b/contracts-c/did/did.c similarity index 100% rename from contracts/did/did.c rename to contracts-c/did/did.c diff --git a/contracts/highvalue/highvalue_block.c b/contracts-c/highvalue/highvalue_block.c similarity index 100% rename from contracts/highvalue/highvalue_block.c rename to contracts-c/highvalue/highvalue_block.c diff --git a/contracts/highvalue/highvalue_prepare.c b/contracts-c/highvalue/highvalue_prepare.c similarity index 100% rename from contracts/highvalue/highvalue_prepare.c rename to contracts-c/highvalue/highvalue_prepare.c diff --git a/contracts/loan/admin.c b/contracts-c/loan/admin.c similarity index 100% rename from contracts/loan/admin.c rename to contracts-c/loan/admin.c diff --git a/contracts/loan/loan.c b/contracts-c/loan/loan.c similarity index 100% rename from contracts/loan/loan.c rename to contracts-c/loan/loan.c diff --git a/contracts/loan/p2p_loan.c b/contracts-c/loan/p2p_loan.c similarity index 100% rename from contracts/loan/p2p_loan.c rename to contracts-c/loan/p2p_loan.c diff --git a/contracts/loan/pool.c b/contracts-c/loan/pool.c similarity index 100% rename from contracts/loan/pool.c rename to contracts-c/loan/pool.c diff --git a/contracts/lottery/lottery.c b/contracts-c/lottery/lottery.c similarity index 100% rename from contracts/lottery/lottery.c rename to contracts-c/lottery/lottery.c diff --git a/contracts/lottery/lottery_end.c b/contracts-c/lottery/lottery_end.c similarity index 100% rename from contracts/lottery/lottery_end.c rename to contracts-c/lottery/lottery_end.c diff --git a/contracts/lottery/lottery_end_ic.c b/contracts-c/lottery/lottery_end_ic.c similarity index 100% rename from contracts/lottery/lottery_end_ic.c rename to contracts-c/lottery/lottery_end_ic.c diff --git a/contracts/lottery/lottery_ic.c b/contracts-c/lottery/lottery_ic.c similarity index 100% rename from contracts/lottery/lottery_ic.c rename to contracts-c/lottery/lottery_ic.c diff --git a/contracts/lottery/lottery_start.c b/contracts-c/lottery/lottery_start.c similarity index 100% rename from contracts/lottery/lottery_start.c rename to contracts-c/lottery/lottery_start.c diff --git a/contracts/oracle/oracle.c b/contracts-c/oracle/oracle.c similarity index 100% rename from contracts/oracle/oracle.c rename to contracts-c/oracle/oracle.c diff --git a/contracts/portfolio/trailing_stop.c b/contracts-c/portfolio/trailing_stop.c similarity index 100% rename from contracts/portfolio/trailing_stop.c rename to contracts-c/portfolio/trailing_stop.c diff --git a/contracts/redirect/redirect.c b/contracts-c/redirect/redirect.c similarity index 100% rename from contracts/redirect/redirect.c rename to contracts-c/redirect/redirect.c diff --git a/contracts/router/router_base.c b/contracts-c/router/router_base.c similarity index 100% rename from contracts/router/router_base.c rename to contracts-c/router/router_base.c diff --git a/contracts/router/router_check_1.c b/contracts-c/router/router_check_1.c similarity index 100% rename from contracts/router/router_check_1.c rename to contracts-c/router/router_check_1.c diff --git a/contracts/router/router_check_2.c b/contracts-c/router/router_check_2.c similarity index 100% rename from contracts/router/router_check_2.c rename to contracts-c/router/router_check_2.c diff --git a/contracts/router/router_check_3.c b/contracts-c/router/router_check_3.c similarity index 100% rename from contracts/router/router_check_3.c rename to contracts-c/router/router_check_3.c diff --git a/contracts/utils/date.h b/contracts-c/utils/date.h similarity index 100% rename from contracts/utils/date.h rename to contracts-c/utils/date.h diff --git a/contracts/utils/error.h b/contracts-c/utils/error.h similarity index 100% rename from contracts/utils/error.h rename to contracts-c/utils/error.h diff --git a/contracts/utils/extern.h b/contracts-c/utils/extern.h similarity index 100% rename from contracts/utils/extern.h rename to contracts-c/utils/extern.h diff --git a/contracts/utils/hookapi.h b/contracts-c/utils/hookapi.h similarity index 100% rename from contracts/utils/hookapi.h rename to contracts-c/utils/hookapi.h diff --git a/contracts/utils/macro.h b/contracts-c/utils/macro.h similarity index 100% rename from contracts/utils/macro.h rename to contracts-c/utils/macro.h diff --git a/contracts/utils/sfcodes.h b/contracts-c/utils/sfcodes.h similarity index 100% rename from contracts/utils/sfcodes.h rename to contracts-c/utils/sfcodes.h diff --git a/contracts/voucher/voucher_claim.c b/contracts-c/voucher/voucher_claim.c similarity index 100% rename from contracts/voucher/voucher_claim.c rename to contracts-c/voucher/voucher_claim.c diff --git a/contracts/voucher/voucher_create.c b/contracts-c/voucher/voucher_create.c similarity index 100% rename from contracts/voucher/voucher_create.c rename to contracts-c/voucher/voucher_create.c diff --git a/contractsjs/@types/global.d.ts b/contracts-js/@types/global.d.ts similarity index 100% rename from contractsjs/@types/global.d.ts rename to contracts-js/@types/global.d.ts diff --git a/contractsjs/oracle/oracle.ts b/contracts-js/oracle/oracle.ts similarity index 100% rename from contractsjs/oracle/oracle.ts rename to contracts-js/oracle/oracle.ts diff --git a/contracts/funds/modular/master.c b/contracts/funds/modular/master.c deleted file mode 100644 index 8ff9054..0000000 --- a/contracts/funds/modular/master.c +++ /dev/null @@ -1,658 +0,0 @@ -//------------------------------------------------------------------------------ -/* - -HookParameters -> State: - -ADM: The admin account (role) -STL: The settler account (role) -RFD: The refunder account (role) -WKEY: The withdrawer pubkey (role) - -Asset States -KEY: (<20 bytes currency><20 bytes issuer>) -DATA: ) - -Operations: - -// invoke ops are: (role) - // I - initalize (any) - // S - settle (settler) - // U/P - un/pause (admin) - // M - modify (admin) - // A - asset (admin) - // R - refund (refunder) - -// invoke (Modify) sub ops are: - // A - modify admin account (role) - // S - modify settler account (role) - // W - modify withdraw pubkey (role) - // D - modify withdraw delay - -// invoke (Asset) sub ops are: - // C - create asset (integration) - Set TrustLine ~ - // U - update asset (integration) - Update Settlement Address - // D - delete asset (integration) - Set Trustline 0 - -*/ -//============================================================================== - -#include "hookapi.h" - -#define SVAR(x) &(x), sizeof(x) - -#define DONE(x)\ - return accept(SBUF(x), __LINE__) - -#define NOPE(x)\ - return rollback(SBUF(x), __LINE__) - - -#define FLIP_ENDIAN_64(n) ((uint64_t)(((n & 0xFFULL) << 56ULL) | \ - ((n & 0xFF00ULL) << 40ULL) | \ - ((n & 0xFF0000ULL) << 24ULL) | \ - ((n & 0xFF000000ULL) << 8ULL) | \ - ((n & 0xFF00000000ULL) >> 8ULL) | \ - ((n & 0xFF0000000000ULL) >> 24ULL) | \ - ((n & 0xFF000000000000ULL) >> 40ULL) | \ - ((n & 0xFF00000000000000ULL) >> 56ULL))) - -uint8_t txn_out[300] = -{ -/* size,upto */ -/* 3, 0 */ 0x12U, 0x00U, 0x00U, /* tt = Payment */ -/* 5, 3 */ 0x22U, 0x80U, 0x00U, 0x00U, 0x00U, /* flags = tfCanonical */ -/* 5, 8 */ 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, /* sequence = 0 */ -/* 6, 13 */ 0x20U, 0x1AU, 0x00U, 0x00U, 0x00U, 0x00U, /* first ledger seq */ -/* 6, 19 */ 0x20U, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, /* last ledger seq */ -/* 1, 25 */ 0x61U, -/* 8, 26 */ 0,0,0,0,0,0,0,0, /* amt val */ -/* 20, 34 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* amt cur */ -// vvvvvvvvvvvvvvvvvv ISSUER ACC ID vvvvvvvvvvvvvvvvvvvvvvv -/* 20, 54 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - -/* 9, 74 */ 0x68U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, /* fee */ -/* 35, 83 */ 0x73U, 0x21U, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* pubkey */ -/* 2, 118 */ 0x81U, 0x14U, /* src acc preamble */ - -/* 20, 120 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* src acc */ -/* 2, 140 */ 0x83U, 0x14U, /* dest acc preamble */ -/* 20, 142 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* dest acc */ - -/* 138, 162 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* emit detail */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -/* 0, 300 */ -}; - -#define TLACC (txn_out + 54) /* set it above!! */ - -#define TXNLEN 300 -#define FEEOUT (txn_out + 75) -#define EMITDET (txn_out + 162) -#define HOOKACC (txn_out + 120) -#define OTXNACC (txn_out + 142) -#define DTAG_OUT (txn_out + 142) -#define DESTACC (txn_out + 142) -#define OUTAMT (txn_out + 25) -#define OUTCUR (txn_out + 34) -#define OUTISS (txn_out + 54) -#define CURSHORT (txn_out + 46) - -// if we make a TrustSet instead (used for initialisation) then we'll truncate the template above -#define TTOUT (txn_out + 2) // when it's a TrustSet we set this to 0x14 -#define OUTAMT_TL (txn_out + 25) // when it's a TrustSet, we set this to 0x63 -#define EMITDET_TL (txn_out + 140) // when it's a TrustSet Emit Details occurs sooner -#define TXNLEN_TL 278 // .. and the txn is smaller - -#define BE_DROPS(drops)\ -{\ - uint64_t drops_tmp = drops;\ - uint8_t* b = (uint8_t*)&drops;\ - *b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\ - *b++ = (drops_tmp >> 48) & 0xFFU;\ - *b++ = (drops_tmp >> 40) & 0xFFU;\ - *b++ = (drops_tmp >> 32) & 0xFFU;\ - *b++ = (drops_tmp >> 24) & 0xFFU;\ - *b++ = (drops_tmp >> 16) & 0xFFU;\ - *b++ = (drops_tmp >> 8) & 0xFFU;\ - *b++ = (drops_tmp >> 0) & 0xFFU;\ -} - -#define COPY_20(src, dst)\ -{\ - *((uint64_t*)(((uint8_t*)(dst)) + 0)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 0));\ - *((uint64_t*)(((uint8_t*)(dst)) + 8)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 8));\ - *((uint32_t*)(((uint8_t*)(dst)) + 16)) = \ - *((uint32_t*)(((uint8_t*)(src)) + 16));\ -} - -#define ACCOUNT_TO_BUF(buf_raw, i) \ -{ \ - unsigned char *buf = (unsigned char *)buf_raw; \ - *(uint64_t *)(buf + 0) = *(uint64_t *)(i + 0); \ - *(uint64_t *)(buf + 8) = *(uint64_t *)(i + 8); \ - *(uint32_t *)(buf + 16) = *(uint32_t *)(i + 16); \ -} - -int64_t cbak(uint32_t f) -{ - // TODO track withdrawal txns to see if they successfully executed - return 0; -} - -int64_t hook(uint32_t r) -{ - _g(1,1); - - etxn_reserve(1); - - uint8_t hook_accid[32]; - hook_account(hook_accid + 12, 20); - - uint8_t otxn_accid[32]; - otxn_field(otxn_accid + 12, 20, sfAccount); - - if (BUFFER_EQUAL_20(hook_accid + 12, otxn_accid + 12)) - DONE("Master: passing outgoing txn"); - - int64_t tt = otxn_type(); - if (tt != ttINVOKE) - NOPE("Master: Rejecting non-Invoke txn."); - - // get admin account (role) - uint8_t _admin[20]; - if (hook_param(SBUF(_admin), "ADM", 3) != 20) - NOPE("Master: Misconfigured. Missing ADM install parameter."); - - // get settlement account (role) - uint8_t _stl[20]; - if (hook_param(SBUF(_stl), "STL", 3) != 20) - NOPE("Master: Misconfigured. Missing STL install parameter."); - - // get the withdrawal signing key - uint8_t _wkey[33]; - if (hook_param(SBUF(_wkey), "WKEY", 4) != 33) - NOPE("Master: Misconfigured. Missing WKEY install parameter."); - - // get withdraw delay - int64_t _delay; - if (hook_param(SVAR(_delay), "DLY", 3) != 4) - NOPE("Master: Misconfigured. Missing DLY install parameter."); - - // Operation - uint8_t op; - if (otxn_param(&op, 1, "OP", 2) != 1) - NOPE("Master: Missing OP parameter on Invoke."); - - // Sub Operation - uint8_t sop; - if ((op == 'M' || op == 'A') && otxn_param(&sop, 1, "SOP", 3) != 1) - NOPE("Master: Missing SOP parameter on Invoke."); - - int64_t xfl_in; - uint32_t flags; - - // enforced pausedness - if (op != 'U') - { - uint8_t paused; - state(&paused, 1, "P", 1); - if (paused) - NOPE("Master: Paused."); - } - - // // enforce initalisation - // if (!already_setup && op != 'I') - // NOPE("Master: Send op=I initalisation first."); - - uint8_t admin[20]; - uint8_t stl[20]; - uint8_t wkey[33]; - uint8_t acc[20]; - int64_t delay; - if (state(SBUF(admin), "ADM", 3) == DOESNT_EXIST) - { - *admin = _admin; - state_set(_admin, 20, "ADM", 3); - *stl = _stl; - state_set(_stl, 20, "STL", 3); - *wkey = _wkey; - state_set(_wkey, 33, "WKEY", 4); - delay = _delay; - state_set(SVAR(_delay), "DLY", 3); - } - else - { - state(SBUF(admin), "ADM", 3); - state(SBUF(stl), "STL", 3); - state(SBUF(wkey), "WKEY", 4); - state(SBUF(acc), "ACC", 3); - state(SVAR(delay), "DLY", 3); - } - - int64_t is_admin = BUFFER_EQUAL_20(otxn_accid + 12, admin); - int64_t is_stl = BUFFER_EQUAL_20(otxn_accid + 12, stl); - - // permission check - if (!is_admin && (op == 'U' || op == 'P' || op == 'M')) - NOPE("Master: Admin only operation."); - - if (!is_stl && (op == 'S' || op == 'R')) - NOPE("Master: Settler only operation."); - - // current ledger seq is used when emitting a txn - int64_t seq = ledger_seq() + 1; - - // action - switch (op) - { - case 'A': - { - switch (sop) - { - case 'C': // create asset (integration) - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Master: Misconfigured. Missing ACC asset parameter."); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("Master: Misconfigured. Missing AMT asset parameter."); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("Master: Misconfigured. Missing AHS asset parameter."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - int64_t already_setup = (slot_set(SBUF(keylet), 10) == 10); - TRACEVAR(already_setup); - if (already_setup) - DONE("Master: Already setup trustline."); - - int64_t xfl_out = *((int64_t *)amt); - - // write limit amount - float_sto(OUTAMT_TL, 49, amt + 8, 20, amt + 28, 20, xfl_out, sfLimitAmount); - - // set the template transaction type to trustset - *TTOUT = 0x14U; - - etxn_details(EMITDET_TL, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN_TL); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN_TL, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN_TL); - TRACEVAR(emit_result); - - TRACEHEX(hash); - state_set(account, 20, SBUF(hash)); - DONE("Master: Created Asset Integration."); - } - - case 'U': // create asset (integration) - { - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Master: Misconfigured. Missing ACC modify parameter."); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("Master: Misconfigured. Missing AHS asset parameter."); - - state_set(account, 20, SBUF(hash)); - DONE("Master: Updated Asset Integration."); - } - - case 'D': // delete asset (integration) - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("Master: Misconfigured. Missing AMT asset parameter."); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("Master: Misconfigured. Missing AHS asset parameter."); - - int64_t xfl_out = *((int64_t *)amt); - - // write limit amount - float_sto(OUTAMT_TL, 49, amt + 8, 20, amt + 28, 20, xfl_out, sfLimitAmount); - - // set the template transaction type to trustset - *TTOUT = 0x14U; - - etxn_details(EMITDET_TL, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN_TL); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN_TL, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN_TL); - TRACEVAR(emit_result); - - TRACEHEX(hash); - state_set(0, 0, SBUF(hash)); - DONE("Master: Deleted Asset Integration."); - } - - default: - { - NOPE("Master: Unknown operation."); - } - } - } - - case 'U': - case 'P': - { - // pause - uint8_t paused = (op == 'P' ? 1 : 0); - state_set(&paused, 1, "P", 1); - DONE("Master: Paused/Unpaused."); - } - - // settlement - case 'S': - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("Master: Misconfigured. Missing AMT otxn parameter."); - int64_t sig_amt = *((int64_t *)amt); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("Master: Misconfigured. Missing AHS otxn parameter."); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Master: Misconfigured. Missing SEQ otxn parameter."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - if (slot_set(SBUF(keylet), 10) != 10) - DONE("Master: Invalid trustline."); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("Master: Could not fetch trustline balance."); - - uint8_t low_limit[48]; - if (slot_subfield(10, sfLowLimit, 13) != 13) - NOPE("Master: Could not slot subfield `sfLowLimit`"); - - if (slot(SVAR(low_limit), 13) != 48) - NOPE("Master: Could not slot `sfLowLimit`"); - - int64_t xfl_bal = slot_float(11); - - // balance is negative and issuer is not low - if (float_sign(xfl_bal) && !BUFFER_EQUAL_20(amt + 28, low_limit + 28)) - { - NOPE("Master: Insane balance on trustline."); - } - - xfl_bal = float_sign(xfl_bal) ? float_negate(xfl_bal) : xfl_bal; - - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("Master: Insane balance on trustline."); - - // set the destination addr to the settlement addr - uint8_t stl_account[20]; - state_set(SBUF(stl_account), SBUF(hash)); - COPY_20(stl_account, DESTACC); - - // check the nonce - uint32_t stl_seq; - state(SVAR(stl_seq), otxn_accid + 12, 20); - - if (stl_seq != sig_nce) - NOPE("Master: Settlement nonce out of sequence."); - - if (sig_amt <= 0) - NOPE("Master: Settlement amount must be greater than 0."); - - TRACEVAR(sig_amt); - TRACEVAR(xfl_bal); - if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER)) - NOPE("Master: Balance not high enough for this settlement."); - - // write payment amount - float_sto(OUTAMT, 49, amt + 8, 20, amt + 28, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("Master: Settle Emitted Failure."); - } - - stl_seq++; - if (state_set(SVAR(stl_seq), otxn_accid + 12, 20) != 4) - NOPE("Master: Failed to set state."); - - DONE("Master: Emitted settlement."); - break; - } - - // refund - case 'R': - { - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("Master: Misconfigured. Missing AMT otxn parameter."); - int64_t sig_amt = *((int64_t *)amt); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Master: Misconfigured. Missing SEQ otxn parameter."); - - uint8_t acct_buff[20]; - if (otxn_param(SVAR(acct_buff), "ACC", 3) != 20) - NOPE("Master: Misconfigured. Missing ACC otxn parameter."); - - COPY_20(acct_buff, DESTACC); - - // check the nonce - uint32_t rfd_seq; - state(SVAR(rfd_seq), otxn_accid + 12, 20); - TRACEVAR(rfd_seq); - - if (rfd_seq != sig_nce) - NOPE("Master: Refund nonce out of sequence."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - if (slot_set(SBUF(keylet), 10) != 10) - DONE("User: Invalid trustline."); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("Master: Could not fetch trustline balance."); - - uint8_t low_limit[48]; - if (slot_subfield(10, sfLowLimit, 13) != 13) - NOPE("Master: Could not slot subfield `sfLowLimit`"); - - if (slot(SVAR(low_limit), 13) != 48) - NOPE("Master: Could not slot `sfLowLimit`"); - - int64_t xfl_bal = slot_float(11); - - // balance is negative and issuer is not low - if (float_sign(xfl_bal) && !BUFFER_EQUAL_20(amt + 28, low_limit + 28)) - { - NOPE("Master: Insane balance on trustline."); - } - - xfl_bal = float_sign(xfl_bal) ? float_negate(xfl_bal) : xfl_bal; - - // check dtag balance - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("Master: Insane balance on balance."); - - if (sig_amt <= 0) - 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 refund."); - - // write payment amount - float_sto(OUTAMT, 49, amt + 8, 20, amt + 28, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("Master: Refund Emitted Failure."); - } - - rfd_seq++; - if (state_set(SVAR(rfd_seq), otxn_accid + 12, 20) != 4) - NOPE("Master: Failed to set state."); - - DONE("Master: Refunded."); - break; - } - - case 'M': - { - switch (sop) - { - case 'A': // admin (role) - { - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Master: Misconfigured. Missing ACC modify parameter."); - - state_set(account, 20, "ADM", 3); - DONE("Master: Admin Modified."); - } - - case 'S': // settler (role) - { - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Master: Misconfigured. Missing ACC modify parameter."); - - state_set(account, 20, "STL", 3); - DONE("Master: Settlement Verifier Modified."); - } - - case 'W': // withdraw (role) - { - uint8_t key[33]; - if (otxn_param(SBUF(key), "KEY", 3) != 33) - NOPE("Master: Misconfigured. Missing KEY modify parameter."); - - state_set(key, 33, "WKEY", 4); - DONE("Master: Withdraw Verifier Modified."); - } - - case 'D': // delay (time) - { - int64_t delay; - if (otxn_param(SVAR(delay), "DLY", 3) != 4) - NOPE("Master: Misconfigured. Missing DLY modify parameter."); - - state_set(SVAR(delay), "DLY", 3); - DONE("Master: Withdraw Delay Modified."); - } - - default: - { - NOPE("Master: Unknown operation."); - } - } - } - - default: - { - NOPE("Master: Unknown operation."); - } - } - - return 0; -} \ No newline at end of file diff --git a/contracts/funds/modular/user.c b/contracts/funds/modular/user.c deleted file mode 100644 index 50a4d8f..0000000 --- a/contracts/funds/modular/user.c +++ /dev/null @@ -1,743 +0,0 @@ -//------------------------------------------------------------------------------ -/* - -Foreign State (Read): - -ADM: The admin account (role) -STL: The settler account (role) -RFD: The refunder account (role) -WKEY: The withdrawer pubkey (role) - -Asset States -KEY: (<20 bytes currency><20 bytes issuer>) -DATA: ) - -Operations: - -// payment ops are: - // D - deposit (any) - -// invoke ops are: - // B - debit (settler) - // W - withdraw (user) - -// invoke (Asset) ops are: - // C - create asset (integration) - Set TrustLine ~ - // D - delete asset (integration) - Set Trustline 0 - -// invoke (Withdraw) ops are: - // A - Approval (user) - // I - Intent (user) - // E - Execution (user) - // C - Cancel (user) - -*/ -//============================================================================== - -#include "hookapi.h" - -#define SVAR(x) &(x), sizeof(x) - -#define DONE(x)\ - return accept(SBUF(x), __LINE__) - -#define NOPE(x)\ - return rollback(SBUF(x), __LINE__) - - -#define FLIP_ENDIAN_64(n) ((uint64_t)(((n & 0xFFULL) << 56ULL) | \ - ((n & 0xFF00ULL) << 40ULL) | \ - ((n & 0xFF0000ULL) << 24ULL) | \ - ((n & 0xFF000000ULL) << 8ULL) | \ - ((n & 0xFF00000000ULL) >> 8ULL) | \ - ((n & 0xFF0000000000ULL) >> 24ULL) | \ - ((n & 0xFF000000000000ULL) >> 40ULL) | \ - ((n & 0xFF00000000000000ULL) >> 56ULL))) - -uint8_t txn_out[300] = -{ -/* size,upto */ -/* 3, 0 */ 0x12U, 0x00U, 0x00U, /* tt = Payment */ -/* 5, 3 */ 0x22U, 0x80U, 0x00U, 0x00U, 0x00U, /* flags = tfCanonical */ -/* 5, 8 */ 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, /* sequence = 0 */ -/* 6, 13 */ 0x20U, 0x1AU, 0x00U, 0x00U, 0x00U, 0x00U, /* first ledger seq */ -/* 6, 19 */ 0x20U, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, /* last ledger seq */ -/* 1, 25 */ 0x61U, -/* 8, 26 */ 0,0,0,0,0,0,0,0, /* amt val */ -/* 20, 34 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* amt cur */ -// vvvvvvvvvvvvvvvvvv ISSUER ACC ID vvvvvvvvvvvvvvvvvvvvvvv -/* 20, 54 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - -/* 9, 74 */ 0x68U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, /* fee */ -/* 35, 83 */ 0x73U, 0x21U, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* pubkey */ -/* 2, 118 */ 0x81U, 0x14U, /* src acc preamble */ - -/* 20, 120 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* src acc */ -/* 2, 140 */ 0x83U, 0x14U, /* dest acc preamble */ -/* 20, 142 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* dest acc */ - -/* 138, 162 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* emit detail */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -/* 0, 300 */ -}; - -#define TLACC (txn_out + 54) /* set it above!! */ - -#define TXNLEN 300 -#define FEEOUT (txn_out + 75) -#define EMITDET (txn_out + 162) -#define HOOKACC (txn_out + 120) -#define OTXNACC (txn_out + 142) -#define DTAG_OUT (txn_out + 142) -#define DESTACC (txn_out + 142) -#define OUTAMT (txn_out + 25) -#define OUTCUR (txn_out + 34) -#define OUTISS (txn_out + 54) -#define CURSHORT (txn_out + 46) - -// if we make a TrustSet instead (used for initialisation) then we'll truncate the template above -#define TTOUT (txn_out + 2) // when it's a TrustSet we set this to 0x14 -#define OUTAMT_TL (txn_out + 25) // when it's a TrustSet, we set this to 0x63 -#define EMITDET_TL (txn_out + 140) // when it's a TrustSet Emit Details occurs sooner -#define TXNLEN_TL 278 // .. and the txn is smaller - -#define BE_DROPS(drops)\ -{\ - uint64_t drops_tmp = drops;\ - uint8_t* b = (uint8_t*)&drops;\ - *b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\ - *b++ = (drops_tmp >> 48) & 0xFFU;\ - *b++ = (drops_tmp >> 40) & 0xFFU;\ - *b++ = (drops_tmp >> 32) & 0xFFU;\ - *b++ = (drops_tmp >> 24) & 0xFFU;\ - *b++ = (drops_tmp >> 16) & 0xFFU;\ - *b++ = (drops_tmp >> 8) & 0xFFU;\ - *b++ = (drops_tmp >> 0) & 0xFFU;\ -} - -#define COPY_20(src, dst)\ -{\ - *((uint64_t*)(((uint8_t*)(dst)) + 0)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 0));\ - *((uint64_t*)(((uint8_t*)(dst)) + 8)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 8));\ - *((uint32_t*)(((uint8_t*)(dst)) + 16)) = \ - *((uint32_t*)(((uint8_t*)(src)) + 16));\ -} - -#define ACCOUNT_TO_BUF(buf_raw, i) \ -{ \ - unsigned char *buf = (unsigned char *)buf_raw; \ - *(uint64_t *)(buf + 0) = *(uint64_t *)(i + 0); \ - *(uint64_t *)(buf + 8) = *(uint64_t *)(i + 8); \ - *(uint32_t *)(buf + 16) = *(uint32_t *)(i + 16); \ -} - -uint8_t master_accid[20] = { - 0x6D, 0xF9, 0x0E, 0xCA, 0x2B, 0x5C, 0x0B, 0x45, 0xAA, 0x2E, - 0x1D, 0x6E, 0x99, 0x3B, 0xF7, 0xD9, 0xDC, 0xB2, 0x26, 0xB3 -}; - -uint8_t ns[32] = { - 0x1D, 0xAE, 0x33, 0x31, 0xAD, 0x54, 0x4F, 0x4F, - 0xB6, 0x1F, 0x34, 0x75, 0x85, 0xDC, 0x39, 0x75, - 0xE5, 0xE3, 0xC1, 0x19, 0xFA, 0x6A, 0xA5, 0xED, - 0x4E, 0x6D, 0x9D, 0x58, 0x0C, 0x77, 0xB2, 0x25 -}; - -uint8_t nonce_ns[32] = { - 0x21, 0x2C, 0xCE, 0x06, 0x94, 0xF0, 0x63, 0xCC, - 0x1D, 0xB8, 0xCF, 0xA3, 0x46, 0xE2, 0x96, 0xF3, - 0xE1, 0xF9, 0xE1, 0xF0, 0xFE, 0x93, 0x12, 0xF6, - 0x87, 0x58, 0x00, 0xBA, 0x70, 0x57, 0x8F, 0xFE -}; - -int64_t cbak(uint32_t f) -{ - // TODO track withdrawal txns to see if they successfully executed - return 0; -} - -int64_t hook(uint32_t r) -{ - _g(1,1); - - etxn_reserve(1); - - uint8_t hook_accid[32]; - hook_account(hook_accid + 12, 20); - - uint8_t otxn_accid[32]; - otxn_field(otxn_accid + 12, 20, sfAccount); - - if (BUFFER_EQUAL_20(hook_accid + 12, otxn_accid + 12)) - DONE("User: passing outgoing txn"); - - int64_t tt = otxn_type(); - if (tt != ttINVOKE && tt != ttPAYMENT) - NOPE("User: Rejecting non-Invoke, non-Payment txn."); - - otxn_slot(1); - - slot_subfield(1, sfAmount, 2); - - uint8_t amt[48]; - - if (slot_size(2) == 8) - DONE("User: Passing incoming XAH payment."); - - // get admin account (role) - uint8_t admin[20]; - if (state_foreign(SBUF(admin), "ADM", 3, SBUF(ns), SBUF(master_accid)) != 20) - NOPE("User: Misconfigured. Missing ADM state."); - - // get settlement account (role) - uint8_t stl[20]; - if (state_foreign(SBUF(stl), "STL", 3, SBUF(ns), SBUF(master_accid)) != 20) - NOPE("User: Misconfigured. Missing STL state."); - - // get the withdrawal signing key - uint8_t wkey[33]; - if (state_foreign(SBUF(wkey), "WKEY", 4, SBUF(ns), SBUF(master_accid)) != 33) - NOPE("User: Misconfigured. Missing WKEY state."); - - // get withdraw delay - // int64_t delay; - // if (state_foreign(SVAR(delay), "DLY", 3, SBUF(ns), SBUF(master_accid)) != 4) - // NOPE("User: Misconfigured. Missing DLY state."); - - // Operation - uint8_t op; - 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 Withdraw or Asset Operation."); - - // 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) - if (flags & 0x200U) - NOPE("User: Partial payments are not supported."); - - otxn_field(SBUF(amt), sfAmount); - - int64_t xfl_in = slot_float(2); - - if (xfl_in < 0 || !float_compare(xfl_in, 0, COMPARE_GREATER)) - NOPE("User: Invalid sfAmount."); - } - - int64_t is_stl = BUFFER_EQUAL_20(otxn_accid + 12, stl); - - // permission check - if (!is_stl && (op == 'B')) - NOPE("User: Settler only operation."); - - // current ledger seq is used when emitting a txn - int64_t seq = ledger_seq() + 1; - - // action - switch (op) - { - case 'A': - { - switch (sop) - { - case 'C': // create asset (integration) - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("User: Misconfigured. Missing AMT asset parameter."); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("User: Misconfigured. Missing AHS asset parameter."); - - uint8_t dump[20]; - TRACEHEX(hash); - if (state_foreign(SBUF(dump), SBUF(hash), SBUF(ns), SBUF(master_accid)) == DOESNT_EXIST) - { - NOPE("User: Asset has not been integrated with Master Contract."); - } - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - int64_t already_setup = (slot_set(SBUF(keylet), 10) == 10); - TRACEVAR(already_setup); - if (already_setup) - DONE("User: Already setup trustline."); - - int64_t xfl_out = *((int64_t *)amt); - - // write limit amount - float_sto(OUTAMT_TL, 49, amt + 8, 20, amt + 28, 20, xfl_out, sfLimitAmount); - - // set the template transaction type to trustset - *TTOUT = 0x14U; - - etxn_details(EMITDET_TL, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN_TL); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN_TL, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN_TL); - TRACEVAR(emit_result); - - DONE("User: Created Asset Integration."); - } - - case 'D': // delete asset (integration) - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("User: Misconfigured. Missing AMT asset parameter."); - - uint8_t hash[32]; - if (otxn_param(SBUF(hash), "AHS", 3) != 32) - NOPE("User: Misconfigured. Missing AHS asset parameter."); - - int64_t xfl_out = *((int64_t *)amt); - - // write limit amount - float_sto(OUTAMT_TL, 49, amt + 8, 20, amt + 28, 20, xfl_out, sfLimitAmount); - - // set the template transaction type to trustset - *TTOUT = 0x14U; - - etxn_details(EMITDET_TL, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN_TL); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN_TL, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN_TL); - TRACEVAR(emit_result); - - DONE("User: Deleted Asset Integration."); - } - - default: - { - NOPE("User: Unknown operation."); - } - } - } - - // debit - case 'B': - { - uint8_t amt[48]; - if (otxn_param(SBUF(amt), "AMT", 3) != 48) - NOPE("User: Misconfigured. Missing AMT otxn parameter."); - int64_t sig_amt = *((int64_t *)amt); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("User: Misconfigured. Missing SEQ otxn parameter."); - - // check the nonce - uint32_t dbt_seq; - state_foreign(SVAR(dbt_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20); - - if (dbt_seq != sig_nce) - NOPE("User: Debit nonce out of sequence."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - if (slot_set(SBUF(keylet), 10) != 10) - DONE("User: Invalid trustline."); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("User: Could not fetch trustline balance."); - - uint8_t low_limit[48]; - if (slot_subfield(10, sfLowLimit, 13) != 13) - NOPE("User: Could not slot subfield `sfLowLimit`"); - - if (slot(SVAR(low_limit), 13) != 48) - NOPE("User: Could not slot `sfLowLimit`"); - - int64_t xfl_bal = slot_float(11); - - // balance is negative and issuer is not low - if (float_sign(xfl_bal) && !BUFFER_EQUAL_20(amt + 28, low_limit + 28)) - { - NOPE("User: Insane balance on trustline."); - } - - xfl_bal = float_sign(xfl_bal) ? float_negate(xfl_bal) : xfl_bal; - - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("User: Insane balance on trustline."); - - int64_t xfl_out; - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - // set the destination addr to the settlement addr - COPY_20(stl, DESTACC); - - if (sig_amt <= 0) - NOPE("User: Must provide AMT param when performing settlement."); - - if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER)) - NOPE("User: Balance not high enough for this settlement."); - - // write payment amount - float_sto(OUTAMT, 49, amt + 8, 20, amt + 28, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("User: Debit Emitted Failure."); - } - - dbt_seq++; - if (state_foreign_set(SVAR(dbt_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20) != 4) - NOPE("User: Failed to set state."); - - DONE("User: Emitted debit."); - break; - } - - // withdrawal - case 'W': - { - switch (sop) - { - case 'A': // approval (signature) - { - // get signature if any - // Signature format is packed binary data of the form: - // <20 byte dest accid><8 byte le xfl amount><4 byte le int expiry timestamp><4 byte le int nonce> - uint8_t sig_buf[256]; - int64_t sig_len = otxn_param(SBUF(sig_buf), "SIG", 3); - - // place pointers according to packed data - uint8_t* sig_acc = sig_buf; - uint64_t sig_amt = *((uint64_t*)(sig_buf + 20)); - COPY_20(sig_buf + 28, OUTCUR); - COPY_20(sig_buf + 48, OUTISS); - // uint64_t sig_cur = *((uint64_t*)(sig_buf + 28)); - // uint64_t sig_iss = *((uint64_t*)(sig_buf + 48)); - uint32_t sig_exp = *((uint32_t*)(sig_buf + 68)); - uint32_t sig_nce = *((uint32_t*)(sig_buf + 72)); - uint8_t* sig = sig_buf + 76; - - if (sig_len > 0) - { - if (sig_len < 120) - NOPE("User: Signature too short."); - - if (!util_verify(sig_buf, 76, sig_buf + 76, sig_len - 76, SBUF(wkey))) - NOPE("User: Signature verification failed."); - } - - if (sig_len <= 0) - NOPE("User: Missing SIG parameter."); - - int64_t time = ledger_last_time(); - if (time > sig_exp) - NOPE("User: Ticket has expired."); - - if (!BUFFER_EQUAL_20(sig_acc, otxn_accid + 12)) - NOPE("User: Wrong account for ticket."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, OUTISS, 20, OUTCUR, 20); - if (slot_set(SBUF(keylet), 10) != 10) - DONE("User: Invalid trustline."); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("User: Could not fetch trustline balance."); - - uint8_t low_limit[48]; - if (slot_subfield(10, sfLowLimit, 13) != 13) - NOPE("User: Could not slot subfield `sfLowLimit`"); - - if (slot(SVAR(low_limit), 13) != 48) - NOPE("User: Could not slot `sfLowLimit`"); - - int64_t xfl_bal = slot_float(11); - - // balance is negative and issuer is not low - if (float_sign(xfl_bal) && !BUFFER_EQUAL_20(OUTISS, low_limit + 28)) - { - NOPE("User: Insane balance on trustline."); - } - - xfl_bal = float_sign(xfl_bal) ? float_negate(xfl_bal) : xfl_bal; - - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("User: Insane balance on trustline."); - - // check the nonce - uint32_t wth_seq; - state_foreign(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20); - TRACEVAR(wth_seq); - - if (wth_seq != sig_nce) - NOPE("User: Nonce out of sequence."); - - // check bal can support withdraw - TRACEVAR(xfl_bal); - TRACEVAR(sig_amt); - if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER)) - NOPE("User: Balance not high enough for this withdrawal."); - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - COPY_20(sig_acc, DESTACC); - - // write payment amount - float_sto(OUTAMT, 49, OUTCUR, 20, OUTISS, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("User: Withdrawal Emitted Failure."); - } - - // update nonce - wth_seq++; - if (state_foreign_set(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20) != 4) - NOPE("User: Failed to set state."); - - DONE("User: Emitted approval withdrawal."); - } - - case 'I': // permissionless (intent) - { - uint8_t amt[56]; - if (otxn_param(amt, 48, "AMT", 3) != 48) - NOPE("User: Misconfigured. Missing AMT otxn parameter."); - int64_t sig_amt = *((int64_t *)amt); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("User: Misconfigured. Missing SEQ otxn parameter."); - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, amt + 28, 20, amt + 8, 20); - if (slot_set(SBUF(keylet), 10) != 10) - DONE("User: Invalid trustline."); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("User: Could not fetch trustline balance."); - - uint8_t low_limit[48]; - if (slot_subfield(10, sfLowLimit, 13) != 13) - NOPE("User: Could not slot subfield `sfLowLimit`"); - - if (slot(SVAR(low_limit), 13) != 48) - NOPE("User: Could not slot `sfLowLimit`"); - - int64_t xfl_bal = slot_float(11); - - // balance is negative and issuer is not low - if (float_sign(xfl_bal) && !BUFFER_EQUAL_20(OUTISS, low_limit + 28)) - { - NOPE("User: Insane balance on trustline."); - } - - xfl_bal = float_sign(xfl_bal) ? float_negate(xfl_bal) : xfl_bal; - - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("User: Insane balance on trustline."); - - // check the nonce - uint32_t wth_seq; - state_foreign(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20); - TRACEVAR(wth_seq); - - if (wth_seq != sig_nce) - NOPE("User: Nonce out of sequence."); - - // check bal can support withdraw - if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER)) - NOPE("User: Balance not high enough for this withdrawal."); - - int64_t time = ledger_last_time() + 1; - uint8_t pending_buff[24]; - COPY_20(otxn_accid + 12, pending_buff); - UINT32_TO_BUF(pending_buff + 20U, sig_nce); - - TRACEHEX(pending_buff); - - INT64_TO_BUF(amt + 48U, time); - if (state_set(SBUF(amt), SBUF(pending_buff)) != 56) - NOPE("User: Could not save pending withdrawal intent."); - - // update nonce - wth_seq++; - if (state_foreign_set(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(nonce_ns), hook_accid + 12, 20) != 4) - NOPE("User: Failed to set state."); - - DONE("User: Created permissionless withdraw intent."); - } - - case 'E': // permissionless (execution) - { - uint8_t pending_buff[24]; - if (otxn_param(SBUF(pending_buff), "WI", 2) != 24) - NOPE("User: Misconfigured. Missing WI otxn parameter."); - - TRACEHEX(pending_buff); - - uint8_t amount_buff[56]; - if (state(SBUF(amount_buff), SBUF(pending_buff)) == DOESNT_EXIST) - NOPE("User: Misconfigured. Withdraw Intent does not exist."); - - int64_t delay_time = UINT64_FROM_BUF(amount_buff + 48); - int64_t time = ledger_last_time(); - if (time < delay_time) - NOPE("User: Need to wait.."); - - uint64_t sig_amt = *((uint64_t*)(amount_buff + 0U)); - - TRACEVAR(sig_amt); - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - COPY_20(pending_buff, DESTACC); - - // write payment amount - float_sto(OUTAMT, 49, amount_buff + 8, 20, amount_buff + 28, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("User: Withdrawal Emitted Failure."); - } - - state_set(0, 0, SBUF(pending_buff)); - - DONE("User: Emitted permissionless withdrawal."); - } - - default: - { - NOPE("User: Unknown operation."); - } - } - } - - default: - { - NOPE("User: Unknown operation."); - } - } - - return 0; -} \ No newline at end of file diff --git a/contracts/funds/monolithic/monolithic.c b/contracts/funds/monolithic/monolithic.c deleted file mode 100644 index 35c1dfc..0000000 --- a/contracts/funds/monolithic/monolithic.c +++ /dev/null @@ -1,836 +0,0 @@ -//------------------------------------------------------------------------------ -/* - -HookParameters -> State: - -ADM: The admin account (role) -STL: The settler account (role) -WKEY: The withdrawer pubkey (role) -WDLY: The withdraw delay (ledgers) - -CUR: The currency allowed in the funding source -ISS: The issuer account allowed in the funding source -ACC: The settlement account (globally per asset) - -Operations: - -// payment ops are: - // D - deposit (any) - -// invoke ops are: (role) - // I - initalize (any) - // C - create "Funding Source" (any) - // B - debit (settler) - // S - settle (settler) - // U/P - un/pause (admin) - // M - modify (admin) - // R - refund (refunder) - // W - withdraw (user) - // A - asset (admin) - -// invoke (Modify) sub ops are: - // A - modify admin account (role) - // S - modify settler account (role) - // W - modify withdraw pubkey (role) - -// invoke (Withdraw) sub ops are: - // A - approval withdrawal (signature) - // P - permissionless withdrawal (delay) - -*/ -//============================================================================== - -#include "hookapi.h" - -#define SVAR(x) &(x), sizeof(x) - -#define DONE(x)\ - return accept(SBUF(x), __LINE__) - -#define NOPE(x)\ - return rollback(SBUF(x), __LINE__) - - -#define FLIP_ENDIAN_64(n) ((uint64_t)(((n & 0xFFULL) << 56ULL) | \ - ((n & 0xFF00ULL) << 40ULL) | \ - ((n & 0xFF0000ULL) << 24ULL) | \ - ((n & 0xFF000000ULL) << 8ULL) | \ - ((n & 0xFF00000000ULL) >> 8ULL) | \ - ((n & 0xFF0000000000ULL) >> 24ULL) | \ - ((n & 0xFF000000000000ULL) >> 40ULL) | \ - ((n & 0xFF00000000000000ULL) >> 56ULL))) - -uint8_t txn_out[300] = -{ -/* size,upto */ -/* 3, 0 */ 0x12U, 0x00U, 0x00U, /* tt = Payment */ -/* 5, 3 */ 0x22U, 0x80U, 0x00U, 0x00U, 0x00U, /* flags = tfCanonical */ -/* 5, 8 */ 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, /* sequence = 0 */ -/* 6, 13 */ 0x20U, 0x1AU, 0x00U, 0x00U, 0x00U, 0x00U, /* first ledger seq */ -/* 6, 19 */ 0x20U, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, /* last ledger seq */ -/* 1, 25 */ 0x61U, -/* 8, 26 */ 0,0,0,0,0,0,0,0, /* amt val */ -/* 20, 34 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* amt cur */ -// vvvvvvvvvvvvvvvvvv ISSUER ACC ID vvvvvvvvvvvvvvvvvvvvvvv -/* 20, 54 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - -/* 9, 74 */ 0x68U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, /* fee */ -/* 35, 83 */ 0x73U, 0x21U, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* pubkey */ -/* 2, 118 */ 0x81U, 0x14U, /* src acc preamble */ - -/* 20, 120 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* src acc */ -/* 2, 140 */ 0x83U, 0x14U, /* dest acc preamble */ -/* 20, 142 */ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, /* dest acc */ - -/* 138, 162 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* emit detail */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -/* 0, 300 */ -}; - -#define TLACC (txn_out + 54) /* set it above!! */ - -#define TXNLEN 300 -#define FEEOUT (txn_out + 75) -#define EMITDET (txn_out + 162) -#define HOOKACC (txn_out + 120) -#define OTXNACC (txn_out + 142) -#define DTAG_OUT (txn_out + 142) -#define DESTACC (txn_out + 142) -#define OUTAMT (txn_out + 25) -#define OUTCUR (txn_out + 34) -#define OUTISS (txn_out + 54) -#define CURSHORT (txn_out + 46) - -// if we make a TrustSet instead (used for initialisation) then we'll truncate the template above -#define TTOUT (txn_out + 2) // when it's a TrustSet we set this to 0x14 -#define OUTAMT_TL (txn_out + 25) // when it's a TrustSet, we set this to 0x63 -#define EMITDET_TL (txn_out + 140) // when it's a TrustSet Emit Details occurs sooner -#define TXNLEN_TL 278 // .. and the txn is smaller - -#define BE_DROPS(drops)\ -{\ - uint64_t drops_tmp = drops;\ - uint8_t* b = (uint8_t*)&drops;\ - *b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\ - *b++ = (drops_tmp >> 48) & 0xFFU;\ - *b++ = (drops_tmp >> 40) & 0xFFU;\ - *b++ = (drops_tmp >> 32) & 0xFFU;\ - *b++ = (drops_tmp >> 24) & 0xFFU;\ - *b++ = (drops_tmp >> 16) & 0xFFU;\ - *b++ = (drops_tmp >> 8) & 0xFFU;\ - *b++ = (drops_tmp >> 0) & 0xFFU;\ -} - -#define COPY_20(src, dst)\ -{\ - *((uint64_t*)(((uint8_t*)(dst)) + 0)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 0));\ - *((uint64_t*)(((uint8_t*)(dst)) + 8)) = \ - *((uint64_t*)(((uint8_t*)(src)) + 8));\ - *((uint32_t*)(((uint8_t*)(dst)) + 16)) = \ - *((uint32_t*)(((uint8_t*)(src)) + 16));\ -} - -#define ACCOUNT_TO_BUF(buf_raw, i) \ -{ \ - unsigned char *buf = (unsigned char *)buf_raw; \ - *(uint64_t *)(buf + 0) = *(uint64_t *)(i + 0); \ - *(uint64_t *)(buf + 8) = *(uint64_t *)(i + 8); \ - *(uint32_t *)(buf + 16) = *(uint32_t *)(i + 16); \ -} - -uint8_t ns[32] = { - 0x21, 0x2C, 0xCE, 0x06, 0x94, 0xF0, 0x63, 0xCC, - 0x1D, 0xB8, 0xCF, 0xA3, 0x46, 0xE2, 0x96, 0xF3, - 0xE1, 0xF9, 0xE1, 0xF0, 0xFE, 0x93, 0x12, 0xF6, - 0x87, 0x58, 0x00, 0xBA, 0x70, 0x57, 0x8F, 0xFE -}; - -#define DELAY 1U - -int64_t cbak(uint32_t f) -{ - // TODO track withdrawal txns to see if they successfully executed - return 0; -} - -int64_t hook(uint32_t r) -{ - _g(1,1); - - etxn_reserve(1); - - uint8_t hook_accid[32]; - hook_account(hook_accid + 12, 20); - - uint8_t otxn_accid[32]; - otxn_field(otxn_accid + 12, 20, sfAccount); - - if (BUFFER_EQUAL_20(hook_accid + 12, otxn_accid + 12)) - DONE("Monolithic: passing outgoing txn"); - - int64_t tt = otxn_type(); - if (tt != ttINVOKE && tt != ttPAYMENT) - NOPE("Monolithic: Rejecting non-Invoke, non-Payment txn."); - - otxn_slot(1); - - slot_subfield(1, sfAmount, 2); - - uint8_t amt[48]; - - if (slot_size(2) == 8) - DONE("Monolithic: Passing incoming XAH payment."); - - // get admin account (role) - uint8_t _admin[20]; - if (hook_param(SBUF(_admin), "ADM", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing ADM install parameter."); - - // get settlement account (role) - uint8_t _stl[20]; - if (hook_param(SBUF(_stl), "STL", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing STL install parameter."); - - // get the withdrawal signing key - uint8_t _wkey[33]; - if (hook_param(SBUF(_wkey), "WKEY", 4) != 33) - NOPE("Monolithic: Misconfigured. Missing WKEY install parameter."); - - // get currency - if (hook_param(OUTCUR, 20, "CUR", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing CUR install parameter."); - - // get currency issuer - if (hook_param(OUTISS, 20, "ISS", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing ISS install parameter."); - - // get settlement account (asset settlement account) - uint8_t acc[20]; - if (hook_param(SBUF(acc), "ACC", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing ACC install parameter."); - - // Operation - uint8_t op; - if (otxn_param(&op, 1, "OP", 2) != 1) - NOPE("Monolithic: Missing OP parameter on Invoke."); - - // Sub Operation - uint8_t sop; - if ((op == 'M' || op == 'W') && otxn_param(&sop, 1, "SOP", 3) != 1) - NOPE("Monolithic: Missing SOP parameter on Invoke."); - - int64_t xfl_in; - uint32_t flags; - uint32_t dtag; - uint8_t fs[20]; - - if (tt == ttPAYMENT) - { - // this will fail if flags isn't in the txn, that's also ok. - otxn_field(&flags, 4, sfFlags); - - // check for partial payments (0x00020000) -> (0x00000200 LE) - if (flags & 0x200U) - NOPE("Monolithic: Partial payments are not supported."); - - otxn_field(SBUF(amt), sfAmount); - - if (!BUFFER_EQUAL_20(amt + 8, OUTCUR)) - NOPE("Monolithic: Wrong currency."); - - if (!BUFFER_EQUAL_20(amt + 28, OUTISS)) - NOPE("Monolithic: Wrong issuer."); - - xfl_in = slot_float(2); - - if (xfl_in < 0 || !float_compare(xfl_in, 0, COMPARE_GREATER)) - NOPE("Monolithic: Invalid sfAmount."); - } - - // enforced pausedness - if (op != 'U') - { - uint8_t paused; - state(&paused, 1, "P", 1); - if (paused) - NOPE("Monolithic: Paused."); - } - - // check if the trustline exists - uint8_t keylet[34]; - util_keylet(keylet, 34, KEYLET_LINE, hook_accid + 12, 20, OUTISS, 20, OUTCUR, 20); - - int64_t already_setup = (slot_set(SBUF(keylet), 10) == 10); - - // enforce initalisation - if (!already_setup && op != 'I') - NOPE("Monolithic: Send op=I initalisation first."); - - uint8_t admin[20]; - uint8_t stl[20]; - uint8_t wkey[33]; - if (already_setup && op != 'I') - { - state(SBUF(admin), "ADM", 3); - state(SBUF(stl), "STL", 3); - state(SBUF(wkey), "WKEY", 4); - } - - int64_t is_admin = BUFFER_EQUAL_20(otxn_accid + 12, admin); - int64_t is_stl = BUFFER_EQUAL_20(otxn_accid + 12, stl); - - // sanity check - if ((op == 'D') && tt != ttPAYMENT) - NOPE("Monolithic: Deposit operations must be a payment transaction."); - - // permission check - if (!is_admin && (op == 'U' || op == 'P' || op == 'M')) - NOPE("Monolithic: Admin only operation."); - - if (!is_stl && (op == 'B' || op == 'S' || op == 'R')) - NOPE("Monolithic: Settler only operation."); - - // current ledger seq is used when emitting a txn - int64_t seq = ledger_seq() + 1; - - uint8_t stl_bal[8]; - state(SBUF(stl_bal), hook_accid + 12, 20); - int64_t stl_bal_xfl = *((int64_t*)stl_bal); - - // action - switch (op) - { - case 'I': - { - if (already_setup) - DONE("Monolithic: Already setup trustline."); - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - // create a trustline ... - uint8_t xfl_buffer[8]; - if (otxn_param(xfl_buffer, 8, "AMT", 3) != 8) - NOPE("Monolithic: Misconfigured. Missing AMT otxn parameter."); - - int64_t xfl_out = *((int64_t *)xfl_buffer); - - // write limit amount - float_sto(OUTAMT_TL, 49, OUTCUR, 20, OUTISS, 20, xfl_out, sfLimitAmount); - - // set the template transaction type to trustset - *TTOUT = 0x14U; - - etxn_details(EMITDET_TL, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN_TL); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN_TL, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN_TL); - TRACEVAR(emit_result); - - state_set(_admin, 20, "ADM", 3); - state_set(_stl, 20, "STL", 3); - state_set(_wkey, 33, "WKEY", 4); - DONE("Monolithic: Emitted TrustSet to initialize."); - } - - case 'U': - case 'P': - { - // pause - uint8_t paused = (op == 'P' ? 1 : 0); - state_set(&paused, 1, "P", 1); - DONE("Monolithic: Paused/Unpaused."); - } - - case 'D': - { - int64_t test = otxn_param(SBUF(fs), "FS", 2); - TRACEVAR(test); - if (otxn_param(SBUF(fs), "FS", 2) != 20) - NOPE("Monolithic: Misconfigured. Missing FS otxn parameter."); - - int64_t dtag_bal_xfl; - state(SVAR(dtag_bal_xfl), SBUF(fs)); - - int64_t final_bal_xfl = float_sum(dtag_bal_xfl, xfl_in); - if (final_bal_xfl < 0) - NOPE("Monolithic: Insane balance on deposit."); - - if (state_set(SVAR(final_bal_xfl), SBUF(fs)) != 8) - NOPE("Monolithic: Failed to set state on deposit."); - - DONE("Monolithic: Deposited."); - } - - // debit - case 'B': - { - if (otxn_param(SBUF(fs), "FS", 2) != 20) - NOPE("Monolithic: Misconfigured. Missing FS otxn parameter."); - - int64_t sig_amt; - if (otxn_param(SVAR(sig_amt), "AMT", 3) != 8 || sig_amt < 0) - NOPE("Monolithic: Misconfigured. Missing AMT otxn parameter."); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Monolithic: Misconfigured. Missing SEQ otxn parameter."); - - // check the nonce - uint32_t dbt_seq; - state_foreign(SVAR(dbt_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20); - - if (dbt_seq != sig_nce) - NOPE("Monolithic: Debit nonce out of sequence."); - - int64_t dtag_bal_xfl; - state(SVAR(dtag_bal_xfl), SBUF(fs)); - - // check dtag balance - if (dtag_bal_xfl <= 0 || !float_compare(dtag_bal_xfl, 0, COMPARE_GREATER)) - NOPE("Monolithic: Insane balance on dtag."); - - if (sig_amt <= 0) - NOPE("Monolithic: Must provide AMT param when performing debit."); - - if (float_compare(sig_amt, dtag_bal_xfl, COMPARE_GREATER)) - NOPE("Monolithic: Balance not high enough for this debit."); - - int64_t sub_dtag_bal_xfl = float_sum(dtag_bal_xfl, float_negate(sig_amt)); - if (state_set(SVAR(sub_dtag_bal_xfl), SBUF(fs)) != 8) - NOPE("Monolithic: Insane balance on fs."); - - int64_t add_stl_bal_xfl = float_sum(stl_bal_xfl, sig_amt); - if (state_set(SVAR(add_stl_bal_xfl), hook_accid + 12, 20) != 8) - NOPE("Monolithic: Insane balance on stl."); - - dbt_seq++; - if (state_foreign_set(SVAR(dbt_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20) != 4) - NOPE("Monolithic: Failed to set state."); - - DONE("Monolithic: Debited."); - break; - } - - // settlement - case 'S': - { - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - - // check trustline balance - slot_subfield(10, sfBalance, 11); - if (slot_size(11) != 48) - NOPE("Monolithic: Could not fetch trustline balance."); - - int64_t xfl_bal = slot_float(11); - - if (xfl_bal <= 0 || !float_compare(xfl_bal, 0, COMPARE_GREATER)) - NOPE("Monolithic: Insane balance on trustline."); - - // set the destination addr to the settlement addr - COPY_20(acc, DESTACC); - - int64_t sig_amt; - if (otxn_param(SVAR(sig_amt), "AMT", 3) != 8 || sig_amt < 0) - NOPE("Monolithic: Misconfigured. Missing AMT otxn parameter."); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Monolithic: Misconfigured. Missing SEQ otxn parameter."); - - // check the nonce - uint32_t stl_seq; - state_foreign(SVAR(stl_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20); - - if (stl_seq != sig_nce) - NOPE("Monolithic: Settlement nonce out of sequence."); - - if (sig_amt <= 0) - NOPE("Monolithic: Settlement amount must be greater than 0."); - - TRACEVAR(sig_amt); - TRACEVAR(xfl_bal); - if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER)) - NOPE("Monolithic: Balance not high enough for this settlement."); - - // write payment amount - float_sto(OUTAMT, 49, OUTCUR, 20, OUTISS, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("Monolithic: Settle Emitted Failure."); - } - - int64_t sub_stl_bal_xfl = float_sum(stl_bal_xfl, float_negate(sig_amt)); - if (state_set(SVAR(sub_stl_bal_xfl), hook_accid + 12, 20) != 8) - NOPE("Monolithic: Insane balance on stl."); - - stl_seq++; - if (state_foreign_set(SVAR(stl_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20) != 4) - NOPE("Monolithic: Failed to set state."); - - DONE("Monolithic: Emitted settlement."); - break; - } - - // withdrawal - case 'W': - { - switch (sop) - { - case 'A': // approval (signature) - { - // get signature if any - // Signature format is packed binary data of the form: - // <20 byte dest accid><8 byte le xfl amount><4 byte le int expiry timestamp><4 byte le int nonce> - uint8_t sig_buf[256]; - int64_t sig_len = otxn_param(SBUF(sig_buf), "SIG", 3); - - // place pointers according to packed data - uint8_t* sig_acc = sig_buf; - uint64_t sig_amt = *((uint64_t*)(sig_buf + 20)); - uint32_t sig_exp = *((uint32_t*)(sig_buf + 28)); - uint32_t sig_nce = *((uint32_t*)(sig_buf + 32)); - uint8_t* sig = sig_buf + 36; - - if (sig_len > 0) - { - if (sig_len < 80) - NOPE("Monolithic: Signature too short."); - - if (!util_verify(sig_buf, 36, sig_buf + 36, sig_len - 36, SBUF(wkey))) - NOPE("Monolithic: Signature verification failed."); - } - - if (sig_len <= 0) - NOPE("Monolithic: Missing SIG parameter."); - - int64_t time = ledger_last_time(); - if (time > sig_exp) - NOPE("Monolithic: Ticket has expired."); - - if (!BUFFER_EQUAL_20(sig_acc, otxn_accid + 12)) - NOPE("Monolithic: Wrong account for ticket."); - - // check dtag balance - int64_t dtag_bal_xfl; - state(SVAR(dtag_bal_xfl), sig_acc, 20); - - // check the nonce - uint32_t wth_seq; - state_foreign(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20); - TRACEVAR(wth_seq); - - if (wth_seq != sig_nce) - NOPE("Monolithic: Nonce out of sequence."); - - // check bal can support withdraw - TRACEVAR(dtag_bal_xfl); - TRACEVAR(sig_amt); - if (float_compare(sig_amt, dtag_bal_xfl, COMPARE_GREATER)) - NOPE("Monolithic: Balance not high enough for this withdrawal."); - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - COPY_20(sig_acc, DESTACC); - - // write payment amount - float_sto(OUTAMT, 49, OUTCUR, 20, OUTISS, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("Monolithic: Withdrawal Emitted Failure."); - } - - int64_t sub_dtag_bal_xfl = float_sum(dtag_bal_xfl, float_negate(sig_amt)); - if (state_set(SVAR(sub_dtag_bal_xfl), sig_acc, 20) != 8) - NOPE("Monolithic: Insane balance on fs."); - - // update nonce - wth_seq++; - if (state_foreign_set(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20) != 4) - NOPE("Monolithic: Failed to set state."); - - DONE("Monolithic: Emitted approval withdrawal."); - } - - case 'I': // permissionless (intent) - { - if (otxn_param(SVAR(fs), "FS", 2) != 20) - NOPE("Monolithic: Misconfigured. Missing FS otxn parameter."); - - int64_t sig_amt; - if (otxn_param(SVAR(sig_amt), "AMT", 3) != 8 || sig_amt < 0) - NOPE("Monolithic: Misconfigured. Missing AMT otxn parameter."); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Monolithic: Misconfigured. Missing SEQ otxn parameter."); - - // check dtag balance - int64_t dtag_bal_xfl; - state(SVAR(dtag_bal_xfl), SBUF(fs)); - - // check the nonce - uint32_t wth_seq; - state_foreign(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20); - TRACEVAR(wth_seq); - - if (wth_seq != sig_nce) - NOPE("Monolithic: Nonce out of sequence."); - - // check bal can support withdraw - if (float_compare(sig_amt, dtag_bal_xfl, COMPARE_GREATER)) - NOPE("Monolithic: Balance not high enough for this withdrawal."); - - int64_t sub_dtag_bal_xfl = float_sum(dtag_bal_xfl, float_negate(sig_amt)); - if (state_set(SVAR(sub_dtag_bal_xfl), SBUF(fs)) != 8) - NOPE("Monolithic: Insane balance on stl."); - - int64_t time = ledger_last_time() + DELAY; - uint8_t pending_buff[24]; - COPY_20(fs, pending_buff); - UINT32_TO_BUF(pending_buff + 20U, sig_nce); - - TRACEHEX(pending_buff); - - uint8_t amount_buff[16]; - INT64_TO_BUF(amount_buff, FLIP_ENDIAN_64(sig_amt)); - INT64_TO_BUF(amount_buff + 8U, time); - - if (state_set(SBUF(amount_buff), SBUF(pending_buff)) != 16) - NOPE("Monolithic: Could not save pending withdrawal intent."); - - // update nonce - wth_seq++; - if (state_foreign_set(SVAR(wth_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20) != 4) - NOPE("Monolithic: Failed to set state."); - - DONE("Monolithic: Created permissionless withdraw intent."); - } - - case 'E': // permissionless (execution) - { - uint8_t pending_buff[24]; - if (otxn_param(SBUF(pending_buff), "WI", 2) != 24) - NOPE("Monolithic: Misconfigured. Missing WI otxn parameter."); - - TRACEHEX(pending_buff); - - uint8_t amount_buff[16]; - if (state(SBUF(amount_buff), SBUF(pending_buff)) == DOESNT_EXIST) - NOPE("Monolithic: Misconfigured. Withdraw Intent does not exist."); - - int64_t delay_time = UINT64_FROM_BUF(amount_buff + 8); - int64_t time = ledger_last_time(); - if (time < delay_time) - NOPE("Monolithic: Need to wait.."); - - uint64_t sig_amt = *((uint64_t*)(amount_buff + 0U)); - - TRACEVAR(sig_amt); - - ACCOUNT_TO_BUF(HOOKACC, hook_accid + 12); - COPY_20(pending_buff, DESTACC); - - // write payment amount - float_sto(OUTAMT, 49, OUTCUR, 20, OUTISS, 20, sig_amt, sfAmount); - - etxn_details(EMITDET, 138); - int64_t fee = etxn_fee_base(txn_out, TXNLEN); - BE_DROPS(fee); - *((uint64_t*)(FEEOUT)) = fee; - - txn_out[15] = (seq >> 24U) & 0xFFU; - txn_out[16] = (seq >> 16U) & 0xFFU; - txn_out[17] = (seq >> 8U) & 0xFFU; - txn_out[18] = seq & 0xFFU; - - seq += 4; - txn_out[21] = (seq >> 24U) & 0xFFU; - txn_out[22] = (seq >> 16U) & 0xFFU; - txn_out[23] = (seq >> 8U) & 0xFFU; - txn_out[24] = seq & 0xFFU; - - trace(SBUF("emit:"), txn_out, TXNLEN, 1); - - uint8_t emithash[32]; - int64_t emit_result = emit(SBUF(emithash), txn_out, TXNLEN); - if (emit_result < 0) - { - NOPE("Monolithic: Withdrawal Emitted Failure."); - } - - state_set(0, 0, SBUF(pending_buff)); - - DONE("Monolithic: Emitted permissionless withdrawal."); - } - - default: - { - NOPE("Monolithic: Unknown operation."); - } - } - } - - // refund - case 'R': - { - if (otxn_param(SBUF(fs), "FS", 2) != 20) - NOPE("Monolithic: Misconfigured. Missing FS otxn parameter."); - - int64_t sig_amt; - if (otxn_param(SVAR(sig_amt), "AMT", 3) != 8 || sig_amt < 0) - NOPE("Monolithic: Misconfigured. Missing AMT otxn parameter."); - - uint32_t sig_nce; - if (otxn_param(SVAR(sig_nce), "SEQ", 3) != 4) - NOPE("Monolithic: Misconfigured. Missing SEQ otxn parameter."); - - // check the nonce - uint32_t rfd_seq; - state_foreign(SVAR(rfd_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20); - TRACEVAR(rfd_seq); - - if (rfd_seq != sig_nce) - NOPE("Monolithic: Refund nonce out of sequence."); - - // check dtag balance - int64_t dtag_bal_xfl; - state(SVAR(dtag_bal_xfl), SBUF(fs)); - - TRACEVAR(dtag_bal_xfl); - TRACEVAR(sig_amt); - - // check dtag balance - if (dtag_bal_xfl <= 0 || !float_compare(dtag_bal_xfl, 0, COMPARE_GREATER)) - NOPE("Monolithic: Insane balance on dtag."); - - if (sig_amt <= 0) - NOPE("Monolithic: Must provide AMT param when performing refund."); - - if (float_compare(sig_amt, dtag_bal_xfl, COMPARE_GREATER)) - NOPE("Monolithic: Balance not high enough for this debit."); - - int64_t add_dtag_bal_xfl = float_sum(dtag_bal_xfl, sig_amt); - if (state_set(SVAR(add_dtag_bal_xfl), SBUF(fs)) != 8) - NOPE("Monolithic: Insane balance on dtag."); - - int64_t sub_stl_bal_xfl = float_sum(stl_bal_xfl, float_negate(sig_amt)); - if (state_set(SVAR(sub_stl_bal_xfl), hook_accid + 12, 20) != 8) - NOPE("Monolithic: Insane balance on stl."); - - rfd_seq++; - if (state_foreign_set(SVAR(rfd_seq), otxn_accid + 12, 20, SBUF(ns), hook_accid + 12, 20) != 4) - NOPE("Monolithic: Failed to set state."); - - DONE("Monolithic: Refunded."); - break; - } - - case 'M': - { - switch (sop) - { - case 'A': // admin (role) - { - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing ACC modify parameter."); - - state_set(account, 20, "ADM", 3); - DONE("Monolithic: ADM Modified."); - } - - case 'S': // settler (role) - { - uint8_t account[20]; - if (otxn_param(SBUF(account), "ACC", 3) != 20) - NOPE("Monolithic: Misconfigured. Missing ACC modify parameter."); - - state_set(account, 20, "STL", 3); - DONE("Monolithic: STL Modified."); - } - - case 'W': // withdraw (role) - { - uint8_t key[33]; - if (otxn_param(SBUF(key), "WKEY", 4) != 33) - NOPE("Monolithic: Misconfigured. Missing KEY modify parameter."); - - state_set(key, 33, "WKEY", 4); - DONE("Monolithic: WKEY Modified."); - } - - default: - { - NOPE("Monolithic: Unknown operation."); - } - } - } - - default: - { - NOPE("Monolithic: Unknown operation."); - } - } - - return 0; -} \ No newline at end of file diff --git a/jest.config.integration.js b/jest.config.integration-c.js similarity index 80% rename from jest.config.integration.js rename to jest.config.integration-c.js index c25fb27..68f11db 100644 --- a/jest.config.integration.js +++ b/jest.config.integration-c.js @@ -2,7 +2,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', - testMatch: ['**/test/integration/**/*.test.ts'], + testMatch: ['**/test/integration-c/**/*.test.ts'], // Set the timeout value for all tests to 2 minutes (default is 5 seconds) testTimeout: 120000, diff --git a/jest.config.integration-js.js b/jest.config.integration-js.js new file mode 100644 index 0000000..4c0d50c --- /dev/null +++ b/jest.config.integration-js.js @@ -0,0 +1,9 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: ['**/test/integration-js/**/*.test.ts'], + + // Set the timeout value for all tests to 2 minutes (default is 5 seconds) + testTimeout: 120000, +} diff --git a/package.json b/package.json index e91971c..73778af 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,10 @@ "version": "0.0.1", "description": "A library of Xahau Hook Standards.", "scripts": { - "build:hooks": "c2wasm-cli contracts build", - "test:integration": "jest --config=jest.config.integration.js --runInBand", + "build:hooks-c": "hooks-toolkit-cli compile-c contracts-c build/", + "build:hooks-js": "hooks-toolkit-cli compile-js contracts-js build/", + "test:integration-c": "jest --config=jest.config.integration-c.js --runInBand", + "test:integration-js": "jest --config=jest.config.integration-c.js --runInBand", "lint": "eslint ./test/**/* --ext .ts", "format": "npx prettier --write ./test" }, @@ -14,7 +16,8 @@ }, "license": "GPL-3.0-or-later", "dependencies": { - "@transia/hooks-toolkit": "^2.0.0-alpha.4", + "@transia/hooks-toolkit": "^2.0.0-alpha.1", + "@transia/hooks-toolkit-cli": "^1.0.5", "@transia/ripple-binary-codec": "^1.4.6-alpha.8", "c2wasm-cli": "^1.0.6", "chai": "^4.3.7", diff --git a/test/integration/auction/README.md b/test/integration-c/auction/README.md similarity index 100% rename from test/integration/auction/README.md rename to test/integration-c/auction/README.md diff --git a/test/integration/auction/auction.test.ts b/test/integration-c/auction/auction.test.ts similarity index 100% rename from test/integration/auction/auction.test.ts rename to test/integration-c/auction/auction.test.ts diff --git a/test/integration/auction/auctionStart.test.ts b/test/integration-c/auction/auctionStart.test.ts similarity index 100% rename from test/integration/auction/auctionStart.test.ts rename to test/integration-c/auction/auctionStart.test.ts diff --git a/test/integration/auction/models/AuctionModel.ts b/test/integration-c/auction/models/AuctionModel.ts similarity index 100% rename from test/integration/auction/models/AuctionModel.ts rename to test/integration-c/auction/models/AuctionModel.ts diff --git a/test/integration/autotransfer/README.md b/test/integration-c/autotransfer/README.md similarity index 100% rename from test/integration/autotransfer/README.md rename to test/integration-c/autotransfer/README.md diff --git a/test/integration/autotransfer/autotransfer.test.ts b/test/integration-c/autotransfer/autotransfer.test.ts similarity index 100% rename from test/integration/autotransfer/autotransfer.test.ts rename to test/integration-c/autotransfer/autotransfer.test.ts diff --git a/test/integration/checkout/README.md b/test/integration-c/checkout/README.md similarity index 100% rename from test/integration/checkout/README.md rename to test/integration-c/checkout/README.md diff --git a/test/integration/checkout/checkout.test.ts b/test/integration-c/checkout/checkout.test.ts similarity index 100% rename from test/integration/checkout/checkout.test.ts rename to test/integration-c/checkout/checkout.test.ts diff --git a/test/integration/checkout/models/SellerArray.ts b/test/integration-c/checkout/models/SellerArray.ts similarity index 100% rename from test/integration/checkout/models/SellerArray.ts rename to test/integration-c/checkout/models/SellerArray.ts diff --git a/test/integration/checkout/models/SellerModel.ts b/test/integration-c/checkout/models/SellerModel.ts similarity index 100% rename from test/integration/checkout/models/SellerModel.ts rename to test/integration-c/checkout/models/SellerModel.ts diff --git a/test/integration/did/did.test.ts b/test/integration-c/did/did.test.ts similarity index 100% rename from test/integration/did/did.test.ts rename to test/integration-c/did/did.test.ts diff --git a/test/integration/did/models/DIDModel.ts b/test/integration-c/did/models/DIDModel.ts similarity index 100% rename from test/integration/did/models/DIDModel.ts rename to test/integration-c/did/models/DIDModel.ts diff --git a/test/integration/highvalue/highvalueBlock.test.ts b/test/integration-c/highvalue/highvalueBlock.test.ts similarity index 100% rename from test/integration/highvalue/highvalueBlock.test.ts rename to test/integration-c/highvalue/highvalueBlock.test.ts diff --git a/test/integration/highvalue/highvaluePrepare.test.ts b/test/integration-c/highvalue/highvaluePrepare.test.ts similarity index 100% rename from test/integration/highvalue/highvaluePrepare.test.ts rename to test/integration-c/highvalue/highvaluePrepare.test.ts diff --git a/test/integration/loan/README.md b/test/integration-c/loan/README.md similarity index 100% rename from test/integration/loan/README.md rename to test/integration-c/loan/README.md diff --git a/test/integration/loan/admin.test.ts b/test/integration-c/loan/admin.test.ts similarity index 100% rename from test/integration/loan/admin.test.ts rename to test/integration-c/loan/admin.test.ts diff --git a/test/integration/loan/loanPool.test.ts b/test/integration-c/loan/loanPool.test.ts similarity index 99% rename from test/integration/loan/loanPool.test.ts rename to test/integration-c/loan/loanPool.test.ts index 62bca40..829e7ee 100644 --- a/test/integration/loan/loanPool.test.ts +++ b/test/integration-c/loan/loanPool.test.ts @@ -19,6 +19,7 @@ import { // clearAllHooksV3, } from '@transia/hooks-toolkit/dist/npm/src' import { IssuedCurrencyAmount } from '@transia/xrpl/dist/npm/models/common' +import { makePayment } from './utils' describe('loanPool', () => { let testContext: XrplIntegrationTestContext diff --git a/test/integration/loan/models/Loan.ts b/test/integration-c/loan/models/Loan.ts similarity index 100% rename from test/integration/loan/models/Loan.ts rename to test/integration-c/loan/models/Loan.ts diff --git a/test/integration/loan/models/Pool.ts b/test/integration-c/loan/models/Pool.ts similarity index 100% rename from test/integration/loan/models/Pool.ts rename to test/integration-c/loan/models/Pool.ts diff --git a/test/integration/loan/models/utils/AmountModel.ts b/test/integration-c/loan/models/utils/AmountModel.ts similarity index 100% rename from test/integration/loan/models/utils/AmountModel.ts rename to test/integration-c/loan/models/utils/AmountModel.ts diff --git a/test/integration/loan/models/utils/IssueModel.ts b/test/integration-c/loan/models/utils/IssueModel.ts similarity index 100% rename from test/integration/loan/models/utils/IssueModel.ts rename to test/integration-c/loan/models/utils/IssueModel.ts diff --git a/test/integration/loan/pool.test.ts b/test/integration-c/loan/pool.test.ts similarity index 100% rename from test/integration/loan/pool.test.ts rename to test/integration-c/loan/pool.test.ts diff --git a/test/integration/loan/utils.ts b/test/integration-c/loan/utils.ts similarity index 100% rename from test/integration/loan/utils.ts rename to test/integration-c/loan/utils.ts diff --git a/test/integration/lottery/README.md b/test/integration-c/lottery/README.md similarity index 100% rename from test/integration/lottery/README.md rename to test/integration-c/lottery/README.md diff --git a/test/integration/lottery/lottery.test.ts b/test/integration-c/lottery/lottery.test.ts similarity index 100% rename from test/integration/lottery/lottery.test.ts rename to test/integration-c/lottery/lottery.test.ts diff --git a/test/integration/lottery/models/LotteryModel.ts b/test/integration-c/lottery/models/LotteryModel.ts similarity index 100% rename from test/integration/lottery/models/LotteryModel.ts rename to test/integration-c/lottery/models/LotteryModel.ts diff --git a/test/integration/oracle/models/OracleArrayModel.ts b/test/integration-c/oracle/models/OracleArrayModel.ts similarity index 100% rename from test/integration/oracle/models/OracleArrayModel.ts rename to test/integration-c/oracle/models/OracleArrayModel.ts diff --git a/test/integration/oracle/models/OracleModel.ts b/test/integration-c/oracle/models/OracleModel.ts similarity index 100% rename from test/integration/oracle/models/OracleModel.ts rename to test/integration-c/oracle/models/OracleModel.ts diff --git a/test/integration/oracle/oracle.js.test.ts b/test/integration-c/oracle/oracle.js.test.ts similarity index 100% rename from test/integration/oracle/oracle.js.test.ts rename to test/integration-c/oracle/oracle.js.test.ts diff --git a/test/integration/oracle/oracle.test.ts b/test/integration-c/oracle/oracle.test.ts similarity index 100% rename from test/integration/oracle/oracle.test.ts rename to test/integration-c/oracle/oracle.test.ts diff --git a/test/integration/portfolio/portfolio.test.ts b/test/integration-c/portfolio/portfolio.test.ts similarity index 100% rename from test/integration/portfolio/portfolio.test.ts rename to test/integration-c/portfolio/portfolio.test.ts diff --git a/test/integration/portfolio/utils.ts b/test/integration-c/portfolio/utils.ts similarity index 100% rename from test/integration/portfolio/utils.ts rename to test/integration-c/portfolio/utils.ts diff --git a/test/integration/redirect/redirect.test.ts b/test/integration-c/redirect/redirect.test.ts similarity index 100% rename from test/integration/redirect/redirect.test.ts rename to test/integration-c/redirect/redirect.test.ts diff --git a/test/integration/router/README.md b/test/integration-c/router/README.md similarity index 100% rename from test/integration/router/README.md rename to test/integration-c/router/README.md diff --git a/test/integration/router/models/HookPosArray.ts b/test/integration-c/router/models/HookPosArray.ts similarity index 100% rename from test/integration/router/models/HookPosArray.ts rename to test/integration-c/router/models/HookPosArray.ts diff --git a/test/integration/router/models/HookPosModel.ts b/test/integration-c/router/models/HookPosModel.ts similarity index 100% rename from test/integration/router/models/HookPosModel.ts rename to test/integration-c/router/models/HookPosModel.ts diff --git a/test/integration/router/router.test.ts b/test/integration-c/router/router.test.ts similarity index 100% rename from test/integration/router/router.test.ts rename to test/integration-c/router/router.test.ts diff --git a/test/integration/voucher/models/VoucherModel.ts b/test/integration-c/voucher/models/VoucherModel.ts similarity index 100% rename from test/integration/voucher/models/VoucherModel.ts rename to test/integration-c/voucher/models/VoucherModel.ts diff --git a/test/integration/voucher/voucher.test.ts b/test/integration-c/voucher/voucher.test.ts similarity index 100% rename from test/integration/voucher/voucher.test.ts rename to test/integration-c/voucher/voucher.test.ts diff --git a/test/integration-js/oracle/models/OracleArrayModel.ts b/test/integration-js/oracle/models/OracleArrayModel.ts new file mode 100644 index 0000000..382b087 --- /dev/null +++ b/test/integration-js/oracle/models/OracleArrayModel.ts @@ -0,0 +1,31 @@ +import { + BaseModel, + Metadata, +} from '@transia/hooks-toolkit/dist/npm/src/libs/binary-models' +import { OracleModel } from './OracleModel' + +export class OracleArrayModel extends BaseModel { + oracles: OracleModel[] + + constructor(oracles: OracleModel[]) { + super() + this.oracles = oracles + } + + getMetadata(): Metadata { + return [ + { + field: 'oracles', + type: 'varModelArray', + modelClass: OracleModel, + maxArrayLength: 100, + }, + ] + } + + toJSON() { + return { + oracles: this.oracles, + } + } +} diff --git a/test/integration-js/oracle/models/OracleModel.ts b/test/integration-js/oracle/models/OracleModel.ts new file mode 100644 index 0000000..eb19b49 --- /dev/null +++ b/test/integration-js/oracle/models/OracleModel.ts @@ -0,0 +1,41 @@ +import { + BaseModel, + Metadata, + Currency, + XRPAddress, + XFL, +} from '@transia/hooks-toolkit/dist/npm/src/libs/binary-models' + +export class OracleModel extends BaseModel { + issuer: XRPAddress + currency: Currency + value: XFL + + // 48 bytes + constructor( + issuer: XRPAddress, // 20 byte / 0 + currency: Currency, // 20 byte / 20 + value: XFL // 8 byte / 40 + ) { + super() + this.issuer = issuer + this.currency = currency + this.value = value + } + + getMetadata(): Metadata { + return [ + { field: 'issuer', type: 'xrpAddress' }, + { field: 'currency', type: 'currency' }, + { field: 'value', type: 'xfl' }, + ] + } + + toJSON() { + return { + issuer: this.issuer, + currency: this.currency, + value: this.value, + } + } +} diff --git a/test/integration-js/oracle/oracle.js.test.ts b/test/integration-js/oracle/oracle.js.test.ts new file mode 100644 index 0000000..443d6d1 --- /dev/null +++ b/test/integration-js/oracle/oracle.js.test.ts @@ -0,0 +1,108 @@ +// xrpl +import { Invoke, SetHookFlags, TransactionMetadata } from '@transia/xrpl' +// xrpl-helpers +import { + XrplIntegrationTestContext, + setupClient, + teardownClient, + serverUrl, +} from '@transia/hooks-toolkit/dist/npm/src/libs/xrpl-helpers' +// src +import { + Xrpld, + SetHookParams, + setHooksV3, + createHookPayload, + ExecutionUtility, + generateHash, + StateUtility, + hexNamespace, + clearHookStateV3, + clearAllHooksV3, + iHook, +} from '@transia/hooks-toolkit/dist/npm/src' +import { OracleModel } from './models/OracleModel' +import { OracleArrayModel } from './models/OracleArrayModel' +import { hexToXfl } from '@transia/hooks-toolkit/dist/npm/src/libs/binary-models' + +// Router: ACCEPT: success + +describe('oracle', () => { + let testContext: XrplIntegrationTestContext + + beforeAll(async () => { + testContext = await setupClient(serverUrl) + const hookWallet = testContext.hook1 + const acct1hook1 = createHookPayload({ + version: 1, + createFile: 'oracle', + namespace: 'oracle', + flags: SetHookFlags.hsfOverride, + hookOnArray: ['Invoke'], + }) + await setHooksV3({ + client: testContext.client, + seed: hookWallet.seed, + hooks: [{ Hook: acct1hook1 }], + } as SetHookParams) + }) + afterAll(async () => { + const clearHook = { + Flags: SetHookFlags.hsfNSDelete, + HookNamespace: hexNamespace('oracle'), + } as iHook + await clearHookStateV3({ + client: testContext.client, + seed: testContext.hook1.seed, + hooks: [{ Hook: clearHook }, { Hook: clearHook }], + } as SetHookParams) + + await clearAllHooksV3({ + client: testContext.client, + seed: testContext.hook1.seed, + } as SetHookParams) + teardownClient(testContext) + }) + + it('oracle - success', async () => { + // Invoke - Update the oracle + const hookWallet = testContext.hook1 + const oracleModel: OracleModel = new OracleModel( + testContext.ic.issuer, + testContext.ic.currency, + 1.2 + ) + const oracleArray: OracleArrayModel = new OracleArrayModel([oracleModel]) + + const builtTx1: Invoke = { + TransactionType: 'Invoke', + Account: hookWallet.classicAddress, + Blob: oracleArray.encode().slice(2, oracleArray.encode().length), + } + + const result1 = await Xrpld.submit(testContext.client, { + wallet: hookWallet, + tx: builtTx1, + }) + const hookExecutions1 = await ExecutionUtility.getHookExecutionsFromMeta( + testContext.client, + result1.meta as TransactionMetadata + ) + expect(hookExecutions1.executions[0].HookReturnString).toMatch( + 'oracle.c: Updated.' + ) + const ns = generateHash( + Buffer.from( + oracleArray.encode().slice(2, oracleArray.encode().length - 16), + 'hex' + ) + ) + const state = await StateUtility.getHookState( + testContext.client, + hookWallet.classicAddress, + ns, + hexNamespace('oracle') + ) + expect(hexToXfl(state.HookStateData) as number).toBe(Number(1.2)) + }) +}) diff --git a/test/integration/funds/modular.test.ts b/test/integration/funds/modular.test.ts deleted file mode 100644 index 5dd5a0b..0000000 --- a/test/integration/funds/modular.test.ts +++ /dev/null @@ -1,810 +0,0 @@ -import { - Client, - Invoke, - Payment, - SetHookFlags, - TransactionMetadata, - unixTimeToRippleTime, -} from '@transia/xrpl' -// xrpl-helpers -import { - serverUrl, - XrplIntegrationTestContext, - setupClient, - teardownClient, - close, -} from '@transia/hooks-toolkit/dist/npm/src/libs/xrpl-helpers' -// src -import { - Xrpld, - SetHookParams, - createHookPayload, - setHooksV3, - iHookParamEntry, - iHookParamName, - iHookParamValue, - ExecutionUtility, - StateUtility, - padHexString, - hexNamespace, - flipHex, - generateHash, -} from '@transia/hooks-toolkit' -import { - currencyToHex, - hexToUInt32, - uint32ToHex, - xflToHex, - xrpAddressToHex, -} from '@transia/hooks-toolkit/dist/npm/src/libs/binary-models' -import { IssuedCurrencyAmount } from '@transia/xrpl/dist/npm/models/common' -import { sign, verify } from '@transia/ripple-keypairs' - -export async function getNextNonce( - client: Client, - hookAccount: string, - nonceAccount: string -): Promise { - try { - const state = await StateUtility.getHookState( - client, - hookAccount, - padHexString(xrpAddressToHex(nonceAccount)), - hexNamespace('nonces') - ) - return Number(hexToUInt32(flipHex(state.HookStateData))) - } catch (error: any) { - console.log(error.message) - return 0 - } -} - -describe('modular - Success Group', () => { - let testContext: XrplIntegrationTestContext - - beforeAll(async () => { - testContext = await setupClient(serverUrl) - - const masterHook = testContext.hook1 - const userHook = testContext.hook2 - - const adminWallet = testContext.frank - const settleInvoker = testContext.grace - const withdrawInvoker = testContext.ivan - - const hookParam1 = new iHookParamEntry( - new iHookParamName('ADM'), - new iHookParamValue(xrpAddressToHex(adminWallet.classicAddress), true) - ) - const hookParam2 = new iHookParamEntry( - new iHookParamName('STL'), - new iHookParamValue(xrpAddressToHex(settleInvoker.classicAddress), true) - ) - const hookParam3 = new iHookParamEntry( - new iHookParamName('WKEY'), - new iHookParamValue(withdrawInvoker.publicKey, true) - ) - const hookParam4 = new iHookParamEntry( - new iHookParamName('DLY'), - new iHookParamValue(flipHex(uint32ToHex(10)), true) - ) - const mhook1 = createHookPayload({ - version: 0, - createFile: 'master', - namespace: 'funds', - flags: SetHookFlags.hsfOverride, - hookOnArray: ['Invoke'], - hookParams: [ - hookParam1.toXrpl(), - hookParam2.toXrpl(), - hookParam3.toXrpl(), - hookParam4.toXrpl(), - ], - }) - await setHooksV3({ - client: testContext.client, - seed: masterHook.seed, - hooks: [{ Hook: mhook1 }], - } as SetHookParams) - - const uhook1 = createHookPayload({ - version: 0, - createFile: 'user', - namespace: 'funds', - flags: SetHookFlags.hsfOverride, - hookOnArray: ['Invoke', 'Payment'], - }) - await setHooksV3({ - client: testContext.client, - seed: userHook.seed, - hooks: [{ Hook: uhook1 }], - } as SetHookParams) - }) - afterAll(async () => { - teardownClient(testContext) - }) - - it('operation (master) - add asset', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - const settlementWallet = testContext.bob - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('A') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('C') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue( - xflToHex(100000) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - true - ) - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('ACC'), - new iHookParamValue( - xrpAddressToHex(settlementWallet.classicAddress), - true - ) - ) - const hash = generateHash( - Buffer.from( - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - 'hex' - ) - ) - const otxnParam5 = new iHookParamEntry( - new iHookParamName('AHS'), - new iHookParamValue(hash, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - otxnParam5.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - console.log(result) - - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Created Asset Integration.' - ) - }) - it('operation (user) - add currency', async () => { - const hookWallet = testContext.hook2 - const aliceWallet = testContext.alice - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('A') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('C') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue( - xflToHex(100000) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - true - ) - ) - const hash = generateHash( - Buffer.from( - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - 'hex' - ) - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('AHS'), - new iHookParamValue(hash, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: aliceWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: aliceWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Created Asset Integration.' - ) - }) - - // it('operation - pause/unpause', async () => { - // const hookWallet = testContext.hook1 - // const adminWallet = testContext.frank - // const otxn1Param1 = new iHookParamEntry( - // new iHookParamName('OP'), - // new iHookParamValue('P') - // ) - // const builtTx1: Invoke = { - // TransactionType: 'Invoke', - // Account: adminWallet.classicAddress, - // Destination: hookWallet.classicAddress, - // HookParameters: [otxn1Param1.toXrpl()], - // } - // const result1 = await Xrpld.submit(testContext.client, { - // wallet: adminWallet, - // tx: builtTx1, - // }) - // const hookExecutions1 = await ExecutionUtility.getHookExecutionsFromMeta( - // testContext.client, - // result1.meta as TransactionMetadata - // ) - // expect(hookExecutions1.executions[0].HookReturnString).toEqual( - // 'Master: Paused/Unpaused.' - // ) - // const otxn2Param1 = new iHookParamEntry( - // new iHookParamName('OP'), - // new iHookParamValue('U') - // ) - // const builtTx2: Invoke = { - // TransactionType: 'Invoke', - // Account: adminWallet.classicAddress, - // Destination: hookWallet.classicAddress, - // HookParameters: [otxn2Param1.toXrpl()], - // } - // const result2 = await Xrpld.submit(testContext.client, { - // wallet: adminWallet, - // tx: builtTx2, - // }) - // const hookExecutions2 = await ExecutionUtility.getHookExecutionsFromMeta( - // testContext.client, - // result2.meta as TransactionMetadata - // ) - // expect(hookExecutions2.executions[0].HookReturnString).toEqual( - // 'Master: Paused/Unpaused.' - // ) - // }) - it('operation - user deposit', async () => { - const hookWallet = testContext.hook2 - const aliceWallet = testContext.alice - - const amount: IssuedCurrencyAmount = { - issuer: testContext.ic.issuer, - currency: testContext.ic.currency, - value: '100', - } - const builtTx: Payment = { - TransactionType: 'Payment', - Account: aliceWallet.classicAddress, - Destination: hookWallet.classicAddress, - Amount: amount, - } - const result = await Xrpld.submit(testContext.client, { - wallet: aliceWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Deposited.' - ) - }) - - it('operation - debit', async () => { - const hookWallet = testContext.hook2 - const settlerInvoker = testContext.grace - - const amount = 10 - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('B') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue( - xflToHex(amount) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - true - ) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - settlerInvoker.classicAddress - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: settlerInvoker.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: settlerInvoker, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Emitted debit.' - ) - }) - - it('operation - user withdrawal (approval)', async () => { - const hookWallet = testContext.hook2 - const userWallet = testContext.alice - const withdrawInvoker = testContext.ivan - - const amount = 5 - const expiration = unixTimeToRippleTime(Date.now() + 3600000) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const hex = - xrpAddressToHex(userWallet.classicAddress) + - xflToHex(amount) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer) + - flipHex(uint32ToHex(expiration)) + - flipHex(uint32ToHex(nonce)) - - const signature = sign(hex, withdrawInvoker.privateKey) - expect(verify(hex, signature, withdrawInvoker.publicKey)).toBe(true) - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('A') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('SIG'), - new iHookParamValue(hex + signature, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Emitted approval withdrawal.' - ) - }) - it('operation - user withdrawal (intent)', async () => { - const hookWallet = testContext.hook2 - const userWallet = testContext.alice - - const amount = 5 - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('I') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue( - xflToHex(amount) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - true - ) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Created permissionless withdraw intent.' - ) - }) - it('operation - user withdrawal (execute)', async () => { - const hookWallet = testContext.hook2 - const userWallet = testContext.alice - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('E') - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('WI'), - new iHookParamValue( - xrpAddressToHex(userWallet.classicAddress) + - uint32ToHex(nonce === 0 ? 0 : nonce - 1), - true - ) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'User: Emitted permissionless withdrawal.' - ) - }) - it('operation - modify (admin)', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - const admin1Wallet = testContext.elsa - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('M') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('A') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('ACC'), - new iHookParamValue(xrpAddressToHex(admin1Wallet.classicAddress), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Admin Modified.' - ) - }) - it('operation - modify (settler)', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.elsa - const settleWallet = testContext.frank - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('M') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('S') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('ACC'), - new iHookParamValue(xrpAddressToHex(settleWallet.classicAddress), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Settlement Verifier Modified.' - ) - }) - it('operation - modify (withdraw verifier)', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.elsa - const withdrawInvoker = testContext.heidi - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('M') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('W') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('KEY'), - new iHookParamValue(withdrawInvoker.publicKey, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Withdraw Verifier Modified.' - ) - }) - it('operation - modify (withdraw delay)', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.elsa - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('M') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('D') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('DLY'), - new iHookParamValue(flipHex(uint32ToHex(10)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Withdraw Delay Modified.' - ) - }) - it('operation (master) - update asset', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - const settlementWallet = testContext.carol - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('A') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('U') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('ACC'), - new iHookParamValue( - xrpAddressToHex(settlementWallet.classicAddress), - true - ) - ) - const hash = generateHash( - Buffer.from( - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - 'hex' - ) - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('AHS'), - new iHookParamValue(hash, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - console.log(result) - - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Updated Asset Integration.' - ) - }) - it('operation (master) - delete asset', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('A') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('D') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue( - xflToHex(0) + - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - true - ) - ) - const hash = generateHash( - Buffer.from( - currencyToHex(testContext.ic.currency) + - xrpAddressToHex(testContext.ic.issuer), - 'hex' - ) - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('AHS'), - new iHookParamValue(hash, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - console.log(result) - - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Master: Deleted Asset Integration.' - ) - }) -}) diff --git a/test/integration/funds/monolithic.test.ts b/test/integration/funds/monolithic.test.ts deleted file mode 100644 index 6caba6d..0000000 --- a/test/integration/funds/monolithic.test.ts +++ /dev/null @@ -1,556 +0,0 @@ -import { - Client, - Invoke, - Payment, - SetHookFlags, - TransactionMetadata, - unixTimeToRippleTime, -} from '@transia/xrpl' -// xrpl-helpers -import { - serverUrl, - XrplIntegrationTestContext, - setupClient, - teardownClient, - close, -} from '@transia/hooks-toolkit/dist/npm/src/libs/xrpl-helpers' -// src -import { - Xrpld, - SetHookParams, - createHookPayload, - setHooksV3, - iHookParamEntry, - iHookParamName, - iHookParamValue, - ExecutionUtility, - StateUtility, - padHexString, - hexNamespace, - flipHex, -} from '@transia/hooks-toolkit' -import { - currencyToHex, - xflToHex, - xrpAddressToHex, - uint32ToHex, - hexToUInt32, -} from '@transia/hooks-toolkit/dist/npm/src/libs/binary-models' -import { IssuedCurrencyAmount } from '@transia/xrpl/dist/npm/models/common' -import { sign, verify } from '@transia/ripple-keypairs' - -export async function getNextNonce( - client: Client, - hookAccount: string, - nonceAccount: string -): Promise { - try { - const state = await StateUtility.getHookState( - client, - hookAccount, - padHexString(xrpAddressToHex(nonceAccount)), - hexNamespace('nonces') - ) - return Number(hexToUInt32(flipHex(state.HookStateData))) - } catch (error: any) { - console.log(error.message) - return 0 - } -} - -describe('funds - Success Group', () => { - let testContext: XrplIntegrationTestContext - - beforeAll(async () => { - testContext = await setupClient(serverUrl) - const hookWallet = testContext.hook1 - // const userWallet = testContext.alice - const settlementWallet = testContext.bob - - const adminWallet = testContext.frank - const settleInvoker = testContext.grace - const refundInvoker = testContext.heidi - const withdrawInvoker = testContext.ivan - - const hookParam1 = new iHookParamEntry( - new iHookParamName('ADM'), - new iHookParamValue(xrpAddressToHex(adminWallet.classicAddress), true) - ) - const hookParam2 = new iHookParamEntry( - new iHookParamName('STL'), - new iHookParamValue(xrpAddressToHex(settleInvoker.classicAddress), true) - ) - const hookParam3 = new iHookParamEntry( - new iHookParamName('RFD'), - new iHookParamValue(xrpAddressToHex(refundInvoker.classicAddress), true) - ) - const hookParam4 = new iHookParamEntry( - new iHookParamName('WKEY'), - new iHookParamValue(withdrawInvoker.publicKey, true) - ) - const hookParam5 = new iHookParamEntry( - new iHookParamName('CUR'), - new iHookParamValue(currencyToHex(testContext.ic.currency), true) - ) - const hookParam6 = new iHookParamEntry( - new iHookParamName('ISS'), - new iHookParamValue(xrpAddressToHex(testContext.ic.issuer), true) - ) - const hookParam7 = new iHookParamEntry( - new iHookParamName('ACC'), - new iHookParamValue( - xrpAddressToHex(settlementWallet.classicAddress), - true - ) - ) - const hook1 = createHookPayload({ - version: 0, - createFile: 'monolithic', - namespace: 'funds', - flags: SetHookFlags.hsfOverride, - hookOnArray: ['Invoke', 'Payment'], - hookParams: [ - hookParam1.toXrpl(), - hookParam2.toXrpl(), - hookParam3.toXrpl(), - hookParam4.toXrpl(), - hookParam5.toXrpl(), - hookParam6.toXrpl(), - hookParam7.toXrpl(), - ], - }) - await setHooksV3({ - client: testContext.client, - seed: hookWallet.seed, - hooks: [{ Hook: hook1 }], - } as SetHookParams) - }) - afterAll(async () => { - teardownClient(testContext) - }) - - it('operation - initialize', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('I') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue(xflToHex(100000), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [otxnParam1.toXrpl(), otxnParam2.toXrpl()], - } - const result = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Emitted TrustSet to initialize.' - ) - }) - - it('operation - pause/unpause', async () => { - const hookWallet = testContext.hook1 - const adminWallet = testContext.frank - const otxn1Param1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('P') - ) - const builtTx1: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [otxn1Param1.toXrpl()], - } - const result1 = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx1, - }) - const hookExecutions1 = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result1.meta as TransactionMetadata - ) - expect(hookExecutions1.executions[0].HookReturnString).toEqual( - 'Monolithic: Paused/Unpaused.' - ) - const otxn2Param1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('U') - ) - const builtTx2: Invoke = { - TransactionType: 'Invoke', - Account: adminWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [otxn2Param1.toXrpl()], - } - const result2 = await Xrpld.submit(testContext.client, { - wallet: adminWallet, - tx: builtTx2, - }) - const hookExecutions2 = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result2.meta as TransactionMetadata - ) - expect(hookExecutions2.executions[0].HookReturnString).toEqual( - 'Monolithic: Paused/Unpaused.' - ) - }) - it('operation - user deposit', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - - const amount: IssuedCurrencyAmount = { - issuer: testContext.ic.issuer, - currency: testContext.ic.currency, - value: '100', - } - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('D') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('FS'), - new iHookParamValue(xrpAddressToHex(userWallet.classicAddress), true) - ) - const builtTx: Payment = { - TransactionType: 'Payment', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - Amount: amount, - HookParameters: [otxnParam1.toXrpl(), otxnParam2.toXrpl()], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Deposited.' - ) - }) - it('operation - debit', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - const settlerInvoker = testContext.grace - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('B') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('FS'), - new iHookParamValue(xrpAddressToHex(userWallet.classicAddress), true) - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue(xflToHex(10), true) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - settlerInvoker.classicAddress - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: settlerInvoker.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: settlerInvoker, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Debited.' - ) - }) - - it('operation - settlement', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - const settlerInvoker = testContext.grace - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('S') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('FS'), - new iHookParamValue(xrpAddressToHex(userWallet.classicAddress), true) - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue(xflToHex(10), true) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - settlerInvoker.classicAddress - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: settlerInvoker.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: settlerInvoker, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Emitted settlement.' - ) - }) - - it('operation - user withdrawal (approval)', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - const withdrawInvoker = testContext.ivan - - const amount = 5 - const expiration = unixTimeToRippleTime(Date.now() + 3600000) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const hex = - xrpAddressToHex(userWallet.classicAddress) + - xflToHex(amount) + - flipHex(uint32ToHex(expiration)) + - flipHex(uint32ToHex(nonce)) - - const signature = sign(hex, withdrawInvoker.privateKey) - expect(verify(hex, signature, withdrawInvoker.publicKey)).toBe(true) - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('A') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('SIG'), - new iHookParamValue(hex + signature, true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Emitted approval withdrawal.' - ) - }) - it('operation - user withdrawal (intent)', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - - const amount = 5 - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('I') - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('FS'), - new iHookParamValue(xrpAddressToHex(userWallet.classicAddress), true) - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue(xflToHex(amount), true) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const otxnParam5 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - otxnParam5.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Created permissionless withdraw intent.' - ) - }) - it('operation - user withdrawal (execute)', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('W') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('SOP'), - new iHookParamValue('E') - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - userWallet.classicAddress - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('WI'), - new iHookParamValue( - xrpAddressToHex(userWallet.classicAddress) + uint32ToHex(nonce - 1), - true - ) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: userWallet.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: userWallet, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Emitted permissionless withdrawal.' - ) - }) - - it('operation - refund', async () => { - const hookWallet = testContext.hook1 - const userWallet = testContext.alice - const settlerInvoker = testContext.grace - - const otxnParam1 = new iHookParamEntry( - new iHookParamName('OP'), - new iHookParamValue('R') - ) - const otxnParam2 = new iHookParamEntry( - new iHookParamName('FS'), - new iHookParamValue(xrpAddressToHex(userWallet.classicAddress), true) - ) - const otxnParam3 = new iHookParamEntry( - new iHookParamName('AMT'), - new iHookParamValue(xflToHex(10), true) - ) - const nonce = await getNextNonce( - testContext.client, - hookWallet.classicAddress, - settlerInvoker.classicAddress - ) - const otxnParam4 = new iHookParamEntry( - new iHookParamName('SEQ'), - new iHookParamValue(flipHex(uint32ToHex(nonce)), true) - ) - const builtTx: Invoke = { - TransactionType: 'Invoke', - Account: settlerInvoker.classicAddress, - Destination: hookWallet.classicAddress, - HookParameters: [ - otxnParam1.toXrpl(), - otxnParam2.toXrpl(), - otxnParam3.toXrpl(), - otxnParam4.toXrpl(), - ], - } - const result = await Xrpld.submit(testContext.client, { - wallet: settlerInvoker, - tx: builtTx, - }) - const hookExecutions = await ExecutionUtility.getHookExecutionsFromMeta( - testContext.client, - result.meta as TransactionMetadata - ) - await close(testContext.client) - expect(hookExecutions.executions[0].HookReturnString).toEqual( - 'Monolithic: Refunded.' - ) - }) -}) diff --git a/yarn.lock b/yarn.lock index be41f50..06f9cdf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -322,6 +322,121 @@ enabled "2.0.x" kuler "^2.0.0" +"@esbuild/aix-ppc64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz#c7184a326533fcdf1b8ee0733e21c713b975575f" + integrity sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ== + +"@esbuild/android-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz#09d9b4357780da9ea3a7dfb833a1f1ff439b4052" + integrity sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A== + +"@esbuild/android-arm@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.21.5.tgz#9b04384fb771926dfa6d7ad04324ecb2ab9b2e28" + integrity sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg== + +"@esbuild/android-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.21.5.tgz#29918ec2db754cedcb6c1b04de8cd6547af6461e" + integrity sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA== + +"@esbuild/darwin-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz#e495b539660e51690f3928af50a76fb0a6ccff2a" + integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ== + +"@esbuild/darwin-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz#c13838fa57372839abdddc91d71542ceea2e1e22" + integrity sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw== + +"@esbuild/freebsd-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz#646b989aa20bf89fd071dd5dbfad69a3542e550e" + integrity sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g== + +"@esbuild/freebsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz#aa615cfc80af954d3458906e38ca22c18cf5c261" + integrity sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ== + +"@esbuild/linux-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz#70ac6fa14f5cb7e1f7f887bcffb680ad09922b5b" + integrity sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q== + +"@esbuild/linux-arm@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz#fc6fd11a8aca56c1f6f3894f2bea0479f8f626b9" + integrity sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA== + +"@esbuild/linux-ia32@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz#3271f53b3f93e3d093d518d1649d6d68d346ede2" + integrity sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg== + +"@esbuild/linux-loong64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz#ed62e04238c57026aea831c5a130b73c0f9f26df" + integrity sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg== + +"@esbuild/linux-mips64el@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz#e79b8eb48bf3b106fadec1ac8240fb97b4e64cbe" + integrity sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg== + +"@esbuild/linux-ppc64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz#5f2203860a143b9919d383ef7573521fb154c3e4" + integrity sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w== + +"@esbuild/linux-riscv64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz#07bcafd99322d5af62f618cb9e6a9b7f4bb825dc" + integrity sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA== + +"@esbuild/linux-s390x@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz#b7ccf686751d6a3e44b8627ababc8be3ef62d8de" + integrity sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A== + +"@esbuild/linux-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz#6d8f0c768e070e64309af8004bb94e68ab2bb3b0" + integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ== + +"@esbuild/netbsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz#bbe430f60d378ecb88decb219c602667387a6047" + integrity sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg== + +"@esbuild/openbsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz#99d1cf2937279560d2104821f5ccce220cb2af70" + integrity sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow== + +"@esbuild/sunos-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz#08741512c10d529566baba837b4fe052c8f3487b" + integrity sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg== + +"@esbuild/win32-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz#675b7385398411240735016144ab2e99a60fc75d" + integrity sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A== + +"@esbuild/win32-ia32@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz#1bfc3ce98aa6ca9a0969e4d2af72144c59c1193b" + integrity sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA== + +"@esbuild/win32-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz#acad351d582d157bb145535db2a6ff53dd514b5c" + integrity sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw== + "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" @@ -676,7 +791,20 @@ dependencies: "@sinonjs/commons" "^3.0.0" -"@transia/hooks-toolkit@^2.0.0-alpha.4": +"@transia/hooks-toolkit-cli@^1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@transia/hooks-toolkit-cli/-/hooks-toolkit-cli-1.0.5.tgz#70a7948925b17e2245ad5213a7f0be1719ff934b" + integrity sha512-So+TrXtePO5hQTJiQeRO0fGmx3+j5Y0X5r7mP34B2nVNOADpKjvJtjhgLFmURdPz1x5E/C9cIHamYYpHoZaLbQ== + dependencies: + axios "^1.3.4" + base64-js "^1.5.1" + commander "^10.0.1" + dotenv "^16.1.4" + esbuild "^0.21.4" + pako "^2.1.0" + reconnecting-websocket "^4.4.0" + +"@transia/hooks-toolkit@^2.0.0-alpha.1": version "2.0.0-alpha.4" resolved "https://registry.yarnpkg.com/@transia/hooks-toolkit/-/hooks-toolkit-2.0.0-alpha.4.tgz#6db674ab963aa52ae55b708c6748f5175350a8ad" integrity sha512-fBQRs8xlpNK6ww1xvDDmKN2I0PuhM1j0XLbDOGFe493QZhIbd4z8ib8irzdmYaHbChzy0QRvYvxSQ7ImHl0+Pw== @@ -1728,6 +1856,35 @@ es6-symbol@^3.1.1, es6-symbol@^3.1.3: d "^1.0.1" ext "^1.1.2" +esbuild@^0.21.4: + version "0.21.5" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.21.5.tgz#9ca301b120922959b766360d8ac830da0d02997d" + integrity sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw== + optionalDependencies: + "@esbuild/aix-ppc64" "0.21.5" + "@esbuild/android-arm" "0.21.5" + "@esbuild/android-arm64" "0.21.5" + "@esbuild/android-x64" "0.21.5" + "@esbuild/darwin-arm64" "0.21.5" + "@esbuild/darwin-x64" "0.21.5" + "@esbuild/freebsd-arm64" "0.21.5" + "@esbuild/freebsd-x64" "0.21.5" + "@esbuild/linux-arm" "0.21.5" + "@esbuild/linux-arm64" "0.21.5" + "@esbuild/linux-ia32" "0.21.5" + "@esbuild/linux-loong64" "0.21.5" + "@esbuild/linux-mips64el" "0.21.5" + "@esbuild/linux-ppc64" "0.21.5" + "@esbuild/linux-riscv64" "0.21.5" + "@esbuild/linux-s390x" "0.21.5" + "@esbuild/linux-x64" "0.21.5" + "@esbuild/netbsd-x64" "0.21.5" + "@esbuild/openbsd-x64" "0.21.5" + "@esbuild/sunos-x64" "0.21.5" + "@esbuild/win32-arm64" "0.21.5" + "@esbuild/win32-ia32" "0.21.5" + "@esbuild/win32-x64" "0.21.5" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"