|
| 1 | +/** |
| 2 | + * @typedef {import('typeorm').MigrationInterface} MigrationInterface |
| 3 | + * @typedef {import('typeorm').QueryRunner} QueryRunner |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Add liquidity management actions and rule for XT/JUSD. |
| 8 | + * |
| 9 | + * Pattern follows XT/dEURO (rule 295, actions 194/230): |
| 10 | + * Action 1: DfxDex withdraw — transfer JUSD from Citrea (asset 411) to XT |
| 11 | + * Action 2: LiquidityPipeline buy — buy JUSD on Citrea (asset 411), then retry Action 1 |
| 12 | + * Rule: target XT/JUSD (asset 425), deficit starts with Action 1 |
| 13 | + * |
| 14 | + * @class |
| 15 | + * @implements {MigrationInterface} |
| 16 | + */ |
| 17 | +module.exports = class AddXtJusdLiquidityManagement1773170888000 { |
| 18 | + name = 'AddXtJusdLiquidityManagement1773170888000'; |
| 19 | + |
| 20 | + /** |
| 21 | + * @param {QueryRunner} queryRunner |
| 22 | + */ |
| 23 | + async up(queryRunner) { |
| 24 | + // Action 1: DfxDex withdraw JUSD (Citrea) → XT (onFailId set after Action 2 is created) |
| 25 | + await queryRunner.query(` |
| 26 | + INSERT INTO "dbo"."liquidity_management_action" ("system", "command", "params", "tag", "onSuccessId", "onFailId") |
| 27 | + VALUES ('DfxDex', 'withdraw', '{"destinationAddress":"XT_EVM_DEPOSIT_ADDRESS","destinationSystem":"XT","assetId":411}', 'XT JUSD', NULL, NULL) |
| 28 | + `); |
| 29 | + |
| 30 | + // Get the ID of Action 1 |
| 31 | + const [{ id: action1Id }] = await queryRunner.query(` |
| 32 | + SELECT "id" FROM "dbo"."liquidity_management_action" |
| 33 | + WHERE "system" = 'DfxDex' AND "command" = 'withdraw' AND "tag" = 'XT JUSD' |
| 34 | + `); |
| 35 | + |
| 36 | + // Action 2: LiquidityPipeline buy JUSD (Citrea, asset 411) → onSuccess chains to Action 1 |
| 37 | + await queryRunner.query(` |
| 38 | + INSERT INTO "dbo"."liquidity_management_action" ("system", "command", "params", "tag", "onSuccessId", "onFailId") |
| 39 | + VALUES ('LiquidityPipeline', 'buy', '{"assetId":411}', 'XT JUSD', ${action1Id}, NULL) |
| 40 | + `); |
| 41 | + |
| 42 | + // Get the ID of Action 2 |
| 43 | + const [{ id: action2Id }] = await queryRunner.query(` |
| 44 | + SELECT "id" FROM "dbo"."liquidity_management_action" |
| 45 | + WHERE "system" = 'LiquidityPipeline' AND "command" = 'buy' AND "tag" = 'XT JUSD' |
| 46 | + `); |
| 47 | + |
| 48 | + // Link Action 1 onFail → Action 2 |
| 49 | + await queryRunner.query(` |
| 50 | + UPDATE "dbo"."liquidity_management_action" |
| 51 | + SET "onFailId" = ${action2Id} |
| 52 | + WHERE "id" = ${action1Id} |
| 53 | + `); |
| 54 | + |
| 55 | + // Rule: XT/JUSD (asset 425), deficit starts with Action 1 |
| 56 | + await queryRunner.query(` |
| 57 | + INSERT INTO "dbo"."liquidity_management_rule" |
| 58 | + ("context", "status", "minimal", "optimal", "maximal", "targetAssetId", "targetFiatId", |
| 59 | + "deficitStartActionId", "redundancyStartActionId", "reactivationTime", "sendNotifications", "delayActivation") |
| 60 | + VALUES |
| 61 | + ('XT', 'Active', 10000, 20000, NULL, 425, NULL, |
| 62 | + ${action1Id}, NULL, 10, 1, 0) |
| 63 | + `); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @param {QueryRunner} queryRunner |
| 68 | + */ |
| 69 | + async down(queryRunner) { |
| 70 | + // Delete rule first (FK to actions) |
| 71 | + await queryRunner.query(` |
| 72 | + DELETE FROM "dbo"."liquidity_management_rule" |
| 73 | + WHERE "context" = 'XT' AND "targetAssetId" = 425 |
| 74 | + `); |
| 75 | + |
| 76 | + // Delete actions |
| 77 | + await queryRunner.query(` |
| 78 | + UPDATE "dbo"."liquidity_management_action" SET "onFailId" = NULL, "onSuccessId" = NULL WHERE "tag" = 'XT JUSD' |
| 79 | + `); |
| 80 | + await queryRunner.query(` |
| 81 | + DELETE FROM "dbo"."liquidity_management_action" WHERE "tag" = 'XT JUSD' |
| 82 | + `); |
| 83 | + } |
| 84 | +}; |
0 commit comments