@indigo-labs/indigo-sdk 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.github/workflows/ci.yml +62 -0
  2. package/.github/workflows/test.yml +44 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierrc +1 -1
  5. package/README.md +52 -7
  6. package/dist/index.d.mts +1064 -182
  7. package/dist/index.d.ts +1064 -182
  8. package/dist/index.js +2565 -561
  9. package/dist/index.mjs +2546 -593
  10. package/eslint.config.mjs +35 -0
  11. package/package.json +61 -43
  12. package/src/contracts/cdp.ts +208 -359
  13. package/src/contracts/collector.ts +13 -6
  14. package/src/contracts/gov.ts +1 -58
  15. package/src/contracts/interest-oracle.ts +139 -39
  16. package/src/contracts/lrp.ts +223 -0
  17. package/src/contracts/one-shot.ts +67 -0
  18. package/src/contracts/stability-pool.ts +684 -0
  19. package/src/contracts/staking.ts +348 -0
  20. package/src/contracts/treasury.ts +30 -13
  21. package/src/helpers/asset-helpers.ts +51 -22
  22. package/src/helpers/helper-txs.ts +30 -0
  23. package/src/helpers/helpers.ts +29 -8
  24. package/src/helpers/indigo-helpers.ts +19 -0
  25. package/src/helpers/interest-oracle.ts +57 -0
  26. package/src/helpers/lucid-utils.ts +62 -16
  27. package/src/helpers/price-oracle-helpers.ts +36 -0
  28. package/src/helpers/stability-pool-helpers.ts +207 -0
  29. package/src/helpers/staking-helpers.ts +94 -0
  30. package/src/helpers/time-helpers.ts +4 -3
  31. package/src/helpers/value-helpers.ts +16 -0
  32. package/src/index.ts +15 -4
  33. package/src/scripts/always-fail-validator.ts +7 -0
  34. package/src/scripts/auth-token-policy.ts +23 -0
  35. package/src/scripts/cdp-creator-validator.ts +46 -2
  36. package/src/scripts/collector-validator.ts +2 -2
  37. package/src/scripts/execute-validator.ts +52 -0
  38. package/src/scripts/gov-validator.ts +44 -0
  39. package/src/scripts/iasset-policy.ts +22 -0
  40. package/src/scripts/interest-oracle-validator.ts +18 -3
  41. package/src/scripts/lrp-validator.ts +23 -0
  42. package/src/scripts/one-shot-policy.ts +62 -0
  43. package/src/scripts/poll-manager-validator.ts +52 -0
  44. package/src/scripts/poll-shard-validator.ts +47 -0
  45. package/src/scripts/price-oracle-validator.ts +26 -0
  46. package/src/scripts/stability-pool-validator.ts +60 -0
  47. package/src/scripts/staking-validator.ts +8 -0
  48. package/src/scripts/version-record-policy.ts +26 -0
  49. package/src/scripts/version-registry.ts +15 -0
  50. package/src/types/generic.ts +99 -6
  51. package/src/types/indigo/cdp-creator.ts +46 -0
  52. package/src/types/indigo/cdp.ts +86 -31
  53. package/src/types/indigo/execute.ts +21 -0
  54. package/src/types/indigo/gov.ts +50 -20
  55. package/src/types/indigo/interest-oracle.ts +55 -5
  56. package/src/types/indigo/lrp.ts +54 -0
  57. package/src/types/indigo/poll-manager.ts +21 -0
  58. package/src/types/indigo/poll-shard.ts +16 -0
  59. package/src/types/indigo/price-oracle.ts +38 -4
  60. package/src/types/indigo/stability-pool.ts +233 -0
  61. package/src/types/indigo/staking.ts +99 -0
  62. package/src/types/indigo/version-record.ts +17 -0
  63. package/src/types/on-chain-decimal.ts +23 -0
  64. package/src/types/one-shot.ts +22 -0
  65. package/src/types/system-params.ts +95 -77
  66. package/tests/data/system-params.json +972 -972
  67. package/tests/datums.test.ts +279 -44
  68. package/tests/endpoints/initialize.ts +1013 -0
  69. package/tests/hash-checks.test.ts +71 -15
  70. package/tests/indigo-test-helpers.ts +115 -0
  71. package/tests/initialize.test.ts +27 -0
  72. package/tests/interest-calculations.test.ts +110 -133
  73. package/tests/interest-oracle.test.ts +90 -0
  74. package/tests/lrp.test.ts +149 -0
  75. package/tests/queries/governance-queries.ts +31 -0
  76. package/tests/queries/iasset-queries.ts +39 -0
  77. package/tests/queries/interest-oracle-queries.ts +13 -0
  78. package/tests/queries/lrp-queries.ts +39 -0
  79. package/tests/queries/price-oracle-queries.ts +27 -0
  80. package/tests/queries/stability-pool-queries.ts +75 -0
  81. package/tests/queries/staking-queries.ts +43 -0
  82. package/tests/stability-pool.test.ts +364 -0
  83. package/tests/staking.test.ts +105 -0
  84. package/tests/test-helpers.ts +38 -0
  85. package/tsconfig.build.json +4 -0
  86. package/tsconfig.json +8 -27
  87. package/vitest.config.ts +9 -0
  88. package/babel.config.cjs +0 -13
  89. package/examples/sample-cdp.ts +0 -43
  90. package/jest.config.js +0 -13
  91. package/src/contracts/cdp-creator.ts +0 -86
  92. package/src/contracts/price-oracle.ts +0 -24
  93. package/src/helpers/cdp-helpers.ts +0 -9
package/dist/index.mjs CHANGED
@@ -1,159 +1,245 @@
1
- // src/contracts/cdp-creator.ts
1
+ // src/contracts/cdp.ts
2
2
  import {
3
- applyParamsToScript,
4
- Constr,
5
- fromText,
6
- validatorToAddress,
7
- validatorToScriptHash
3
+ applyParamsToScript as applyParamsToScript3,
4
+ Constr as Constr3,
5
+ credentialToAddress as credentialToAddress3,
6
+ Data as Data10,
7
+ fromText as fromText4,
8
+ validatorToAddress as validatorToAddress3,
9
+ validatorToScriptHash as validatorToScriptHash3
8
10
  } from "@lucid-evolution/lucid";
9
11
 
10
- // src/scripts/cdp-creator-validator.ts
11
- var _cdpCreatorValidator = {
12
- type: "PlutusV2",
13
- description: "",
14
- cborHex: "591a6c591a6901000032323232323232322232322323225333009323232533300c3006300e37540022646464646464646464646464646464646464a66603c603660406ea80644c8c8c8ccccc8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c88888c8c8c8c8c8c94ccc0f8c0ecc100dd50008991919192999821181e18221baa00213232533304433034490115496e636f72726563742074782076616c69646974790032325333046325333047302d00114a22a66608e6082002294452818241baa3301d303930493754004607260926ea80044c94ccc11cc1100045288a99982398208008a5114a060906ea8cc074c0c4c124dd5001181898249baa00114a06034606e66094606e660946036660946ea0cdc08071bad30163048375408897ae03304a3330454a298103d87a80004c0103d87980004bd7019825181b99825180d998251ba83370001c6eb4c058c120dd502225eb80cc128ccc11528a6103d87a80004c0103d87980004bd7025eb80c064c058c11cdd501d0a9998221981a24811754582069736e74207369676e6564206279206f776e657200330283758602a608e6ea80e804054ccc110cc0d124011543445043726561746f724e4654206d697373696e67003302e3756605e608e6ea8c0bcc11cdd5003181b98239baa04315333044330344912043445043726561746f72206f757470757420646f6573206e6f74206d617463680033333014008301a330490054bd70260107d87b9fd87980ff00301330373047375408698103d87a80001533304433034491174d696e7465642076616c756520697320696e76616c6964003375e6e98c0c8dd5981898239baa03a374c66660306026604e608e6ea810cdd7181798239baa043375c606e608e6ea800803c54ccc110cc0d1240115434450206f757470757420697320696e76616c69640033333014008303633049301a33049304a304b304b304b304b304b3047375408697ae04bd7019ba548010cc124c0d8cc124c0d8cc124c0d8cc124dd480825eb80cc124c0dcc11cdd5001198249ba800f33049303633049375001a660926ea0cdc01bad303730473754002a66608866e20dd6981398239baa00100d13370666e0ccdc119b823370201a6eb4c09cc11cdd50009bad303730473754605e608e6ea8005208080a0f6f4acdbe01b48202c227efa8052080897a15330454901254d75737420686f6c643a206e6f77203e206c61737420696e7465726573742075706461746500164bd7025eb812f5c097ae033012301330273047375408601c980103d87980001325332330463303649115556e646572636f6c6c61746572697a65642043445000337126eb4c0e4c124dd51980c9980c981998249baa00430383304b3750600202297ae03039304937540046eb4c0e4c124dd51980c981c198259ba830010104bd70181c198259ba833704906400a410112f497ae01533304633036491164e6f6e706f736974697665206d696e74656420616d7400302e011153330463303649012e4d7573742070726f76696465206d6f7265207468616e206d696e436f6c6c61746572616c496e4c6f76656c61636500337126eb4c060c124dd50228080a9998231981b249174f7261636c652063616e2774206265206578706972656400333046325333047304130493754002266e24dd6981918251baa003375a609a60946ea800454cc121240124496e636f7272656374207472616e73616374696f6e2076616c69646974792072616e67650016303930493754606260926ea8c060c124dd501e2504a226606c9201194d757374207061792064656274206d696e74696e67206665650033322232533304a3032002132533304b3232302c00232533304d304a00115333051305037540042930b0a99982698238008a99982898281baa00214985854ccc134c0cc00454ccc144c140dd50010a4c2c2c609c6ea8004c94ccc130c124c138dd50008982918279baa001153304d49117436f756c64206e6f742066696e642072656465656d6572001632323300100100722533305200114c0103d87a8000132323253330513375e00c60a600626086660ac00297ae0133005005002305300230560023054001302133050303e304e375400297ae013333301b00f302133050303d33050002330504c103d87a80004bd7025eb8130107d87b9fd87980ff00330193756606c609c6ea8c0d8c138dd5000801a60103d879800014a064a66609e0022a66098921284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400161533304f305200113051001153304c4901284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400163303301123375e607c609c6ea8c0f8c138dd5181b18271baa00100214a2603e6609c6ea40092f5c06eacc130c134c134c134c134c134c134c134c134c134c124dd501e1bae30133049375408a6644a66609066e2400520001480004dd6981d98259baa303a3304d375066e0cc00cdd6981d98259baa3301b303a3304d375000297ae0002375a607660966ea8c0e8cc134dd419b8248320052080897a4bd7025eb80c04cc124dd50021bad303930493754660326070660966ea00452f5c0607260926ea80085280a5014a06e092080897a14a064a66608a6084608e6ea800454cc11924012543616e6e6f74206f70656e206120434450206f6620612064656c69737465642061737365740016132320025333046304330483754002264646464a66609c60a20042649318118018b1bad304f001304f002304d001304937540022c6054605060906ea8c0c0c120dd51929998250008a99823a492145787065637465642065786163746c79206f6e65206f7261636c6520696e70757400161533304a304d0011304c001153304749012145787065637465642065786163746c79206f6e65206f7261636c6520696e707574001633302c00a304b30483754609660906ea8005300103d8798000302f3047375400429405280a5014a0294052819190012999822182098231baa0011323232323232533304e3051002132498c08c00c58dd698278009827801182680098268011bad304b001304737540022c6050604c608c6ea8c0b8c118dd51929998240008a99822a492a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e707574001615333048304b0011304a001153304549012a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e707574001633302a008302630463754002980103d87980003048304537540042c64a666084607e00226464a6660906096004264932999822182098231baa001132323232323232325333050305300213232498c94ccc138c12c0044c8c8c8c94ccc158c16400852616375a60ae00260ae0046eb4c154004c144dd50018a9998271824000899191919299982b182c8010a4c2c6eb4c15c004c15c008dd6982a80098289baa00316304f3754004604800e2c60a200260a20046eb4c13c004c13c008dd718268009826801182580098239baa00116163049001304537540042a666084607800226464a6660906096004264932999822182098231baa001132323232323232323232323232323232323232323232323232323232533306430670021323232323232323232323232498c10c030c10c03cc108040c104044c100048c0fc04cc0f8050c0f4054c0f0058c0ec05cc0f4060c94ccc184c1780044c8c94ccc19cc1a80084c926303c001163068001306437540342a6660c260b600226464a6660ce60d4004264932999831983018329baa001132325333069306c002132498c10400458c1a8004c198dd50008b0b183400098321baa01a16306237540322c60ca00260ca00464a6660c460c20022a6660bc60b060c0002294454ccc178c16cc1800045280b0b1baa3063001306300230610013061002305f001305f002305d001305d002305b001305b0023059001305900230570013057002305500130550023053001305300230510013051002304f001304f002304d001304d002375c6096002608e6ea80045858c124004c114dd50010b18219baa0013025302330433754605660866ea8c94ccc11400454cc10924012145787065637465642065786163746c79206f6e652069617373657420696e707574001615333045304800113047001153304249012145787065637465642065786163746c79206f6e652069617373657420696e707574001633302700530463047304730473043375407e980103d8798000303230423754605460846ea8004c110c104dd50008b198170020189bac304230430023758608200260820046eb0c0fc004c0ecdd50171181d181d981d981d981d981d981d800911999804001244100488100001233225333034302e4800052f5bded8c0264646600200297adef6c6022533303b00113303c337606ea4014dd3001a5eb7bdb1804c8c8c8c94ccc0ecc068cc0540240084cc100cdd81ba9009374c00e00a2a66607666e3c0240084cc100cdd81ba9009374c00e00626608066ec0dd48011ba6001330060060033756607a0066eb8c0ec008c0fc008c0f4004c8cc0040052f5bded8c044a66607400226607666ec0dd4801a610101004bd6f7b630099191919299981d180c9980a00380109981f99bb0375200e9810101000051533303a3371e00e00426607e66ec0dd4803a6101010000313303f337606ea4008dd4000998030030019bad303c003375c6074004607c00460780026eb8c094c0d4dd50009bae301d303537540024444464660020026603e00ca66606c606660706ea80144c88cdd79815981d9baa302b303b3754002004607860726ea80144c88cdd79815981d9baa001002303c3039375400a44a66607600229404c94ccc0e0c94ccc0e4cdd7980e181e1baa001007132533303e00114a22a66607c60820022646464a66607a60586eb8c10c00c54ccc0f4c0b000454ccc0f4c0e8c0fcdd50048a99981e99b89480000084cdc48012410137dc0429404cdc4a400000429405281bae30423043002375a6082608460840026eb0c1000045281919800800991998008009bab3026303e3754006646600200201244a666082002297adef6c6013233043337606ea4dd718200009ba632330010013756608400444a666088002297adef6c6013233046337606ea4dd718218009ba83370290001bad3044001330030033048002304600133003003304500230430012225333041002100113233300400430450033333301b002375c60800026eacc104004888c94ccc108c0740045300103d87a80001303433047374c00297ae03233300100100300222253330480021001132333004004304c00333333023002375c608e0026eb4c120004888c94ccc124c1180045300103d87a80001303b3304e375000297ae03370000400203e6094004030608600444a66607e002297ae01323332223233001001003225333045001100313233047374e6608e6ea4018cc11cdd49bae30440013304737506eb4c1140052f5c0660060066092004608e0026eb8c0f8004dd5981f80099801801982180118208008a50303e00214a2266006006002607c0024606c606e606e606e606e606e606e606e606e0024606a606c606c606c606c606c606c606c002446042660686ea0cdc199b82375a604460646ea8008dd6981118191baa0014820225e92f5c04444a666060605a002200826666601a0080066464004646600200200444a66606e002293099299981c0008a4c26464a66606c606660706ea8cc040dd7181c181e0021bae30380021330050053303b0020011533037491326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016303c002303a001303a00133035337606ea4008dd4000a5eb7bdb180888c94ccc0d0c03c004530103d87a80001302633039374c00297ae033333011001005004222325333037303400114c103d87a8000130293303c375000297ae03370000200401a0144603c6606264a66605a604e605e6ea80044c94ccc0b8c94ccc0ccc0c800454ccc0bcc0a4c0c40045288a999817981618188008a5016163754603260626ea8c084c0c4dd500189802198199ba80014bd7009802198199ba833700002900125eb80dd6981998181baa0011001301f302f3754603e605e6ea8004cc0c4c94ccc0b4c09cc0bcdd5000899299981719299981998190008a999817981498188008a511533302f302c303100114a02c2c6ea8c064c0c4dd5180c98189baa0031300433033375000297ae01300433033375066e0000520014bd701bad3033303037540022002603e605e6ea8c05cc0bcdd5000a5eb80dd2a40044464a66605860520022a6660586052605c6ea8008530103d87a800014c103d87980001533302c30120011533302c3012302e3754004298103d87a800014c103d87b800013232533302e3028001132533302f33710006002298103d87980001533302f337100020062980103d87b800014c103d87a8000375a606860626ea801054ccc0b8c0ac004530103d87b800014c103d8798000302f37540066eb4c0c8c0bcdd500198169baa002232533302a30270011323253330303033002149858dd7181880098169baa0021533302a30240011533302e302d37540042930b0b18159baa001253330283025302a375400226464a66605c60620042930b1bad302f001302b37540022c44a66605066e40008004530103d8798000153330283371e0040022980103d87a800014c103d87b80002533302a00114a2294094ccc094c088c09cdd5000899191919299981698180010a4c2c6eb8c0b8004c0b8008dd7181600098141baa0011622222323300100100622533302e00113302f337606ea4018dd3002a5eb7bdb1804c8c8c8c94ccc0b8c034cc01c0280084cc0cccdd81ba900a374c01200a2a66605c66e3c0280084c94ccc0bcc0b0c0c4dd500089981a19bb03752016606a60646ea80040104010ccc0200280240044cc0cccdd81ba9002374c0026600c00c0066eacc0c000cdd718170011819001181800091111191980080080311299981680089981719bb0375200c6ea00152f5bded8c0264646464a66605a60186600e01400426606466ec0dd48051ba80090051533302d3371e014004264a66605c605660606ea80044cc0cccdd81ba900b303430313754002008200866601001401200226606466ec0dd48011ba800133006006003375a605e0066eb8c0b4008c0c4008c0bc004dd7a6103d8798000375c604e0066eb4c09c008dd698138009bad302730280013027001302600130213754032266646464446464646464a666050604a60546ea80044c94ccc0a4c08cc0acdd500089919192999818181980109919192999817981618189baa00113301f3300f3303437526e61241084d697373696e6720003303437526e60038cc0d0dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd7024900330133010301d009375c606a60646ea800454cc0c0cc03ccc0d0dd49b98491084d697373696e6720003303437526e60038cc0d0dd49b9849010d20757067726164652070617468004bd70249001632533302f302930313754002298103d87a8000130213303437526eb8c0c8c8cdd8181b000981b181b8009bac30353032375400297ae032330010013756603460646ea800c894ccc0d00045300103d87a80001323253330323371e6eb8c0d00080244c090cc0dcdd39981b981a0011981b981a80125eb812f5c02660080080026070004606c002a66605a6054605e6ea80044c8c8c8c94ccc0d4c0e00084c926323300100100222533303700114984c8cc00c00cc0ec008c8c8dd7181c0011bae30360013039001163756606c002606c0046eb4c0d0004c0c0dd50008b1808980798179baa3017302f37540022c606200266602200a01098103d8798000375c605e60586ea800458c06cc0acdd5180d98159baa3013302b3754605c60566ea800458cc060dd6181680200d9bab302c302d302d302d002375860560026056002604c6ea806488dcc9919199800800802244100222533302a0021001132333004004302e00353330273024371a00426e600044cdc500119b8a00537300026e64dd718160011b98001300100122533302400114bd7009981298111813000998010011813800a490a43445043726561746f7200300b3021375403a46048604a604a00244646600200200644a66604800229404c94ccc084cdc79bae302700200414a2266006006002604e0024a6660386004603c6ea80044c088c07cdd50008a9980ea481134e6f7420616e20696e6c696e6520646174756d0016370e9002111191980300211801180498109baa001533301c3019301e3754002246600e6eacc020c080dd50008018918029998049bab3008302037540026eb8c040c080dd50019bae3008302037540066e21200022323300100100322533301f00114bd7009919299980e980280109981100119802002000899802002000981180118108009118091998020011bae300b301b37540026eb8c00cc06cdd50009180e180e80091119299980c1809180d1baa0011480004dd6980f180d9baa0013253330183012301a37540022980103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a80001323232533301d3371e00e6eb8c07c00c4c03ccc088dd4000a5eb804cc014014008dd6980f80118110011810000991980080080211299980e8008a6103d87a80001323232533301c3371e00e6eb8c07800c4c038cc084dd3000a5eb804cc014014008dd5980f0011810801180f8009180d180d980d980d980d8009191980080080111299980c8008a5eb7bdb1804c8c8c8c94ccc064c020008400c4cc078cdd81ba9002374c0026600c00c0066eacc06c00cdd7180c801180e801180d8009b8f4881002253330123330120014a094454cc04c0084004400488c8cc00400400c894ccc05c0045300103d87a80001323253330153375e601060306ea80080144c01ccc0680092f5c0266008008002603600460320026e952000230140013012300f37540022c60226024004602000260186ea80045261365632533300830050011323232323232323253330143017002149858dd6980a800980a8011bad30130013013002375a602200260220046eb8c03c004c02cdd50018a99980418010008a99980618059baa00314985858c024dd50011b8748008c94ccc014c008c01c00454ccc024c020004526161637540046e1d20005734ae7155ceaab9e5573eae815d0aba21"
15
- };
12
+ // src/helpers/asset-helpers.ts
13
+ import { fromText } from "@lucid-evolution/lucid";
16
14
 
17
- // src/helpers/lucid-utils.ts
18
- import { addAssets, paymentCredentialOf, stakeCredentialOf } from "@lucid-evolution/lucid";
19
- async function addrDetails(lucid) {
20
- const addr = await lucid.wallet().address();
21
- return [
22
- paymentCredentialOf(addr),
23
- stakeCredentialOf(addr)
24
- ];
15
+ // src/types/indigo/cdp.ts
16
+ import { Data as Data4 } from "@lucid-evolution/lucid";
17
+
18
+ // src/types/generic.ts
19
+ import {
20
+ credentialToAddress,
21
+ Data,
22
+ getAddressDetails
23
+ } from "@lucid-evolution/lucid";
24
+ var AssetClassSchema = Data.Object({
25
+ currencySymbol: Data.Bytes(),
26
+ /** Use the HEX encoding */
27
+ tokenName: Data.Bytes()
28
+ });
29
+ var OutputReferenceSchema = Data.Object({
30
+ txHash: Data.Object({ hash: Data.Bytes({ minLength: 32, maxLength: 32 }) }),
31
+ outputIndex: Data.Integer()
32
+ });
33
+ var VerificationKeyHashSchema = Data.Bytes({
34
+ minLength: 28,
35
+ maxLength: 28
36
+ });
37
+ var CredentialSchema = Data.Enum([
38
+ Data.Object({
39
+ PublicKeyCredential: Data.Tuple([VerificationKeyHashSchema])
40
+ }),
41
+ Data.Object({
42
+ ScriptCredential: Data.Tuple([
43
+ Data.Bytes({ minLength: 28, maxLength: 28 })
44
+ ])
45
+ })
46
+ ]);
47
+ var Credential = CredentialSchema;
48
+ var AddressSchema = Data.Object({
49
+ paymentCredential: CredentialSchema,
50
+ stakeCredential: Data.Nullable(
51
+ Data.Enum([
52
+ Data.Object({ Inline: Data.Tuple([CredentialSchema]) }),
53
+ Data.Object({
54
+ Pointer: Data.Tuple([
55
+ Data.Object({
56
+ slotNumber: Data.Integer(),
57
+ transactionIndex: Data.Integer(),
58
+ certificateIndex: Data.Integer()
59
+ })
60
+ ])
61
+ })
62
+ ])
63
+ )
64
+ });
65
+ var Address = AddressSchema;
66
+ function addressToBech32(lucid, address) {
67
+ const paymentCredential = "PublicKeyCredential" in address.paymentCredential ? { type: "Key", hash: address.paymentCredential.PublicKeyCredential[0] } : { type: "Script", hash: address.paymentCredential.ScriptCredential[0] };
68
+ const stakeCredential = address.stakeCredential && "Inline" in address.stakeCredential ? "PublicKeyCredential" in address.stakeCredential.Inline[0] ? {
69
+ type: "Key",
70
+ hash: address.stakeCredential.Inline[0].PublicKeyCredential[0]
71
+ } : {
72
+ type: "Script",
73
+ hash: address.stakeCredential.Inline[0].ScriptCredential[0]
74
+ } : void 0;
75
+ return credentialToAddress(
76
+ lucid.config().network,
77
+ paymentCredential,
78
+ stakeCredential
79
+ );
25
80
  }
26
- async function scriptRef(ref, lucid) {
27
- const utxos = await lucid.utxosByOutRef([{ txHash: ref.input.transactionId, outputIndex: ref.input.index }]);
28
- if (utxos.length === 0)
29
- throw "Unable to locate script ref.";
30
- return utxos[0];
81
+ function addressFromBech32(address) {
82
+ const details = getAddressDetails(address);
83
+ return {
84
+ paymentCredential: {
85
+ PublicKeyCredential: [details.paymentCredential.hash]
86
+ },
87
+ stakeCredential: details.stakeCredential ? { Inline: [{ PublicKeyCredential: [details.stakeCredential.hash] }] } : void 0
88
+ };
31
89
  }
32
- function balance(utxos) {
33
- return utxos.reduce((acc, utxo) => addAssets(acc, utxo.assets), {});
90
+
91
+ // src/types/on-chain-decimal.ts
92
+ import { Data as Data2 } from "@lucid-evolution/lucid";
93
+ var OCD_DECIMAL_UNIT = 1000000n;
94
+ var OnChainDecimalSchema = Data2.Object({
95
+ getOnChainInt: Data2.Integer()
96
+ });
97
+ function ocdMul(a, b) {
98
+ return {
99
+ getOnChainInt: a.getOnChainInt * b.getOnChainInt / OCD_DECIMAL_UNIT
100
+ };
101
+ }
102
+ function ocdDiv(a, b) {
103
+ return {
104
+ getOnChainInt: a.getOnChainInt * OCD_DECIMAL_UNIT / b.getOnChainInt
105
+ };
34
106
  }
35
- var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
36
107
 
37
- // src/contracts/cdp-creator.ts
38
- var CDPCreatorContract = class _CDPCreatorContract {
39
- static address(params, lucid) {
40
- const network = lucid.config().network;
41
- if (!network) {
42
- throw new Error("Network configuration is undefined");
43
- }
44
- return validatorToAddress(network, _CDPCreatorContract.validator(params));
45
- }
46
- static validator(params) {
47
- return {
48
- type: "PlutusV2",
49
- script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
50
- new Constr(0, [
51
- new Constr(0, [
52
- params.cdpCreatorNft[0].unCurrencySymbol,
53
- fromText(params.cdpCreatorNft[1].unTokenName)
54
- ]),
55
- params.cdpAssetCs.unCurrencySymbol,
56
- new Constr(0, [
57
- params.cdpAuthTk[0].unCurrencySymbol,
58
- fromText(params.cdpAuthTk[1].unTokenName)
59
- ]),
60
- new Constr(0, [
61
- params.iAssetAuthTk[0].unCurrencySymbol,
62
- fromText(params.iAssetAuthTk[1].unTokenName)
63
- ]),
64
- new Constr(0, [
65
- params.versionRecordToken[0].unCurrencySymbol,
66
- fromText(params.versionRecordToken[1].unTokenName)
67
- ]),
68
- params.cdpScriptHash,
69
- params.collectorValHash,
70
- BigInt(params.minCollateralInLovelace),
71
- BigInt(params.biasTime)
72
- ])
73
- ])
74
- };
75
- }
76
- static validatorHash(params) {
77
- return validatorToScriptHash(_CDPCreatorContract.validator(params));
78
- }
79
- static redeemer(hash, mintedAmount, collateralAmount, currentTime) {
80
- if (hash.type !== "Key") throw new Error("Cannot support script hash.");
81
- return new Constr(0, [
82
- hash.hash,
83
- BigInt(mintedAmount),
84
- BigInt(collateralAmount),
85
- currentTime
86
- ]);
87
- }
88
- static scriptRef(params, lucid) {
89
- return scriptRef(params.cdpCreatorValidatorRef, lucid);
90
- }
91
- };
108
+ // src/types/indigo/price-oracle.ts
109
+ import { Data as Data3 } from "@lucid-evolution/lucid";
110
+ var OracleAssetNftSchema = Data3.Object({
111
+ oracleNft: Data3.Object({ asset: AssetClassSchema })
112
+ });
113
+ var PriceOracleParamsSchema = Data3.Object({
114
+ owner: Data3.Bytes(),
115
+ /** Milliseconds */
116
+ biasTime: Data3.Integer(),
117
+ /** Milliseconds */
118
+ expiration: Data3.Integer()
119
+ });
120
+ var PriceOracleParams = PriceOracleParamsSchema;
121
+ var PriceOracleDatumSchema = Data3.Object({
122
+ price: OnChainDecimalSchema,
123
+ expiration: Data3.Integer()
124
+ });
125
+ var PriceOracleDatum = PriceOracleDatumSchema;
126
+ function parsePriceOracleDatum(datum) {
127
+ return Data3.from(datum, PriceOracleDatum);
128
+ }
129
+ function serialisePriceOracleDatum(datum) {
130
+ return Data3.to(datum, PriceOracleDatum);
131
+ }
132
+ function castPriceOracleParams(params) {
133
+ return Data3.castTo(params, PriceOracleParams);
134
+ }
92
135
 
93
- // src/contracts/cdp.ts
94
- import {
95
- applyParamsToScript as applyParamsToScript4,
96
- Constr as Constr7,
97
- Data as Data7,
98
- fromText as fromText5,
99
- toText,
100
- validatorToAddress as validatorToAddress4,
101
- validatorToScriptHash as validatorToScriptHash4
102
- } from "@lucid-evolution/lucid";
136
+ // src/types/indigo/cdp.ts
137
+ import { match, P } from "ts-pattern";
138
+ var CDPFeesSchema = Data4.Enum([
139
+ Data4.Object({
140
+ ActiveCDPInterestTracking: Data4.Object({
141
+ lastSettled: Data4.Integer(),
142
+ unitaryInterestSnapshot: Data4.Integer()
143
+ })
144
+ }),
145
+ Data4.Object({
146
+ FrozenCDPAccumulatedFees: Data4.Object({
147
+ lovelacesTreasury: Data4.Integer(),
148
+ lovelacesIndyStakers: Data4.Integer()
149
+ })
150
+ })
151
+ ]);
152
+ var CDPContentSchema = Data4.Object({
153
+ cdpOwner: Data4.Nullable(Data4.Bytes()),
154
+ iasset: Data4.Bytes(),
155
+ mintedAmt: Data4.Integer(),
156
+ cdpFees: CDPFeesSchema
157
+ });
158
+ var IAssetContentSchema = Data4.Object({
159
+ /** Use the HEX encoding */
160
+ assetName: Data4.Bytes(),
161
+ price: Data4.Enum([
162
+ Data4.Object({ Delisted: OnChainDecimalSchema }),
163
+ Data4.Object({
164
+ Oracle: OracleAssetNftSchema
165
+ })
166
+ ]),
167
+ interestOracleNft: AssetClassSchema,
168
+ redemptionRatio: OnChainDecimalSchema,
169
+ maintenanceRatio: OnChainDecimalSchema,
170
+ liquidationRatio: OnChainDecimalSchema,
171
+ debtMintingFeePercentage: OnChainDecimalSchema,
172
+ liquidationProcessingFeePercentage: OnChainDecimalSchema,
173
+ stabilityPoolWithdrawalFeePercentage: OnChainDecimalSchema,
174
+ redemptionReimbursementPercentage: OnChainDecimalSchema,
175
+ redemptionProcessingFeePercentage: OnChainDecimalSchema,
176
+ interestCollectorPortionPercentage: OnChainDecimalSchema,
177
+ firstIAsset: Data4.Boolean(),
178
+ nextIAsset: Data4.Nullable(Data4.Bytes())
179
+ });
180
+ var CDPDatumSchema = Data4.Enum([
181
+ Data4.Object({ CDP: Data4.Object({ content: CDPContentSchema }) }),
182
+ Data4.Object({ IAsset: Data4.Object({ content: IAssetContentSchema }) })
183
+ ]);
184
+ var CDPDatum = CDPDatumSchema;
185
+ function parseCDPDatum(datum) {
186
+ return match(Data4.from(datum, CDPDatum)).with({ CDP: { content: P.select() } }, (res) => res).otherwise(() => {
187
+ throw new Error("Expected an CDP datum.");
188
+ });
189
+ }
190
+ function serialiseCDPDatum(cdpDatum) {
191
+ return Data4.to({ CDP: { content: cdpDatum } }, CDPDatum);
192
+ }
193
+ function parseIAssetDatum(datum) {
194
+ return match(Data4.from(datum, CDPDatum)).with({ IAsset: { content: P.select() } }, (res) => res).otherwise(() => {
195
+ throw new Error("Expected an IAsset datum.");
196
+ });
197
+ }
198
+ function serialiseIAssetDatum(iassetDatum) {
199
+ return Data4.to({ IAsset: { content: iassetDatum } }, CDPDatum);
200
+ }
103
201
 
104
202
  // src/helpers/asset-helpers.ts
105
- import { fromText as fromText2 } from "@lucid-evolution/lucid";
106
203
  var IAssetHelpers = class {
107
- static async findIAssetByRef(outRef, params, lucid) {
108
- throw new Error("Not implemented");
204
+ static async findIAssetByRef(outRef, lucid) {
205
+ return lucid.utxosByOutRef([outRef]).then(
206
+ (utxos) => utxos.map((utxo) => {
207
+ if (!utxo.datum) return void 0;
208
+ const datum = parseIAssetDatum(utxo.datum);
209
+ return { utxo, datum };
210
+ }).find((utxo) => utxo !== void 0)
211
+ ).then((result) => {
212
+ if (!result)
213
+ throw new Error("Unable to locate IAsset by output reference.");
214
+ return result;
215
+ });
109
216
  }
110
217
  static async findIAssetByName(assetName, params, lucid) {
111
218
  return lucid.utxosAtWithUnit(
112
219
  CDPContract.address(params.cdpParams, lucid),
113
- params.cdpParams.iAssetAuthToken[0].unCurrencySymbol + fromText2(params.cdpParams.iAssetAuthToken[1].unTokenName)
114
- ).then((utxos) => utxos.map((utxo) => {
115
- if (!utxo.datum) return void 0;
116
- const datum = CDPContract.decodeCdpDatum(utxo.datum);
117
- if (datum.type !== "IAsset") return void 0;
118
- if (datum.name !== assetName) return void 0;
119
- return { utxo, datum };
120
- }).find((utxo) => utxo !== void 0)).then((result) => {
121
- if (!result) throw "Unable to locate IAsset by name.";
220
+ params.cdpParams.iAssetAuthToken[0].unCurrencySymbol + fromText(params.cdpParams.iAssetAuthToken[1].unTokenName)
221
+ ).then(
222
+ (utxos) => utxos.map((utxo) => {
223
+ if (!utxo.datum) return void 0;
224
+ const datum = parseIAssetDatum(utxo.datum);
225
+ if (datum.assetName !== fromText(assetName)) return void 0;
226
+ return { utxo, datum };
227
+ }).find((utxo) => utxo !== void 0)
228
+ ).then((result) => {
229
+ if (!result) throw new Error("Unable to locate IAsset by name.");
122
230
  return result;
123
231
  });
124
232
  }
125
233
  };
126
234
 
127
- // src/contracts/price-oracle.ts
128
- import { Constr as Constr2, Data as Data2 } from "@lucid-evolution/lucid";
129
- var PriceOracleContract = class {
130
- static decodePriceOracleDatum(datum) {
131
- const oracleDatum = Data2.from(datum);
132
- if (oracleDatum.index != 0 || oracleDatum.fields.length !== 2 || oracleDatum.fields[0].index !== 0)
133
- throw "Invalid Price Oracle Datum provided.";
134
- return {
135
- price: oracleDatum.fields[0].fields[0],
136
- expiration: oracleDatum.fields[1]
137
- };
138
- }
139
- static encodePriceOracleDatum(datum) {
140
- return Data2.to(
141
- new Constr2(0, [
142
- new Constr2(0, [datum.price]),
143
- datum.expiration
144
- ])
145
- );
146
- }
147
- };
148
-
149
235
  // src/contracts/collector.ts
150
236
  import {
151
- applyParamsToScript as applyParamsToScript2,
152
- Constr as Constr3,
153
- Data as Data3,
154
- fromText as fromText3,
155
- validatorToAddress as validatorToAddress2,
156
- validatorToScriptHash as validatorToScriptHash2
237
+ applyParamsToScript,
238
+ Constr,
239
+ Data as Data5,
240
+ fromText as fromText2,
241
+ validatorToAddress,
242
+ validatorToScriptHash
157
243
  } from "@lucid-evolution/lucid";
158
244
 
159
245
  // src/scripts/collector-validator.ts
@@ -163,22 +249,87 @@ var _collectorValidator = {
163
249
  cborHex: "590e7f590e7c010000323232323232323222323223232322533300a323232533300d3007300f37540022646464646464646464a6466602e60280122646464646464a66603a6034603e6ea80044c8c94ccc07ccc03524012f4d757374207370656e642073696e676c6520636f6c6c6563746f7220696e7075742077697468206f6e6c79204144410032533302400114a02a666048604e00226466ebcc058c090dd5180b18121baa001374c64a666044603e002297adef6c6013232330010014bd6f7b63011299981480089981519bb04c01014000374c00697adef6c60132323232533302930123300e48810000213302e337609801014000374c00e00a2a666052602600426605c66ec13001014000374c00e00626605c66ec0dd48011ba600133006006003375660560066eb8c0a4008c0b4008c0ac004c8cc0040052f5bded8c044a66605000226605266ec13001014000375000697adef6c60132323232533302830113300d48810000213302d337609801014000375000e00a2a666050602400426605a66ec13001014000375000e00626605a66ec0dd48011ba800133006006003375a60540066eb8c0a0008c0b0008c0a8004ccc030dd5980b18121baa30163024375400291100488100302600114a0660166eb0c040c088dd500a919baf301130233754602260466ea8c054c08cdd5000801099806a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650033322232330010013300f0045333023302030253754006264466ebcc058c0a0dd5180b18141baa001002302930263754006264466ebcc058c0a0dd5000801181498131baa00322533302800114a0264a66604a64a66604c66ebcc04cc0a4dd5000a60107d87b9fd87980ff00132533302b00114a22a666056605c0022646464a66605460286eb8c0c000c54ccc0a8c05000454ccc0a8c09cc0b0dd526103d87a80001533302a337129000001099b89002482026fb808528099b89480000085280a50375c605e60600046eb4c0b8c0bcc0bc004dd618168008a503233001001323330010013756603a60566ea800cc8cc004004020894ccc0b800452f5bded8c02646606066ec0dd49bae302d001374c64660020026eacc0bc008894ccc0c400452f5bded8c02646606666ec0dd49bae3030001375066e052000375a606200266006006606a00460660026600600660640046060002444a66605c00420022646660080086064006666660240046eb8c0b4004dd59817000911192999817980a8008a60103d87a80001301f33034374c00297ae0323330010010030022225333035002100113233300400430390033333301a002375c60680026eb4c0d4004888c94ccc0d8c0cc0045300103d87a8000130263303b375000297ae03370000400202e606e004020606000444a666058002297ae01323332223233001001003225333032001100313233034374e660686ea4018cc0d0dd49bae30310013303437506eb4c0c80052f5c066006006606c00460680026eb8c0ac004dd5981600099801801981800118170008a50302b00214a226600600600260560026eb0c030c088dd500a99ba548008cc090c03ccc090004cc091300103d87a80004bd7025eb80c94ccc080c069200010011333330070014881003232002323300100100222533302700114984c94ccc0a0004526132325333026302330283754660166eb8c0a0c0b0010dd71814001099802802998158010008a99813a49326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016302c002302a001302a00133025337609810140004c010101004bd6f7b63011119299981218050008a60103d87a80001301433029374c00297ae03333300b0014890048008888c94ccc09cc090004530103d87a8000130173302c375000297ae03370000200401000a6eacc050c088dd5180a18111baa00214a0601e60426ea8c03cc084dd5180998109baa0013023302037540022c660166eb0c034c07cdd500900791299980e99b9000200114c103d87980001533301d3371e0040022980103d87a800014c103d87b80002533301f00114a2294088888c8cc004004018894ccc0900044cc094cdd81ba9006374c00a97adef6c601323232325333024300d3300700a002133029337606ea4028dd30048028a99981219b8f00a002132533302530223027375400226605466ec0dd4805981598141baa001004100433300800a009001133029337606ea4008dd3000998030030019bab3026003375c60480046050004604c00244444646600200200c44a66604600226604866ec0dd48031ba80054bd6f7b630099191919299981198061980380500109981419bb037520146ea002401454ccc08ccdc78050010992999812181098131baa001133029337606ea402cc0a8c09cdd5000802080219980400500480089981419bb037520046ea0004cc01801800cdd698128019bae302300230270023025001375e98103d87980001325333018301200a13233007491334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d65720032533301e00114a02a66603c60420022646466ebc009300103d87b800032533301c30190011323253330223025002149858dd71811800980f9baa0021533301c301600115333020301f37540042930b0a99980e180a8008a999810180f9baa00214985854ccc070cdc3a400c00226464a666044604a0042930b1bad3023001301f37540042a66603866e1d200800115333020301f37540042930b0a99980e19b874802800454ccc080c07cdd50010a4c2c2a66603866e1d200c00115333020301f37540042930b0b180e9baa00132533301b3018301d375400226042603c6ea800454cc071240117436f756c64206e6f742066696e642072656465656d6572001632323300100137566044604660466046604660466046604660466046603e6ea8048894ccc0840045300103d87a8000132323253330203375e00c6044006260206604a00297ae01330050050023022002302500230230013374a90011980f9805980e9baa30200014bd700a50330053758601460386ea803c8cc00cdd59807980e9baa300f301d3754002004601260366ea805c4cccc8c8c8888c8c8c8c8c94ccc08cc080c094dd50008992999812180f18131baa0011323232533302b302e0021323232533302a3027302c3754002266030660206605e6ea4dcc2481084d697373696e6720003302f37526e6003ccc0bcdd49b984901172075706772616465206d696e74696e6720706f6c696379004bd70249003322323300100100322533303200114a0264a66605e66e3cdd7181a8010020a5113300300300130350013011323300100100a22533303000114bd6f7b6300991919192999818180d001080189981a99bb037520046e98004cc01801800cdd598190019bae303000230340023032001375c6060605a6ea800454cc0accc040cc0bcdd49b98491084d697373696e6720003302f37526e6003ccc0bcdd49b9849010d20757067726164652070617468004bd70249001632533302a3024302c3754002298103d87a80001301a3302f37526eb8c0b4c8cdd81818800981898190009bac3030302d375400297ae032330010013756603e605a6ea800c894ccc0bc0045300103d87a800013232533302d3371e6eb8c0bc0080244c074cc0c8dd399819181780119819181800125eb812f5c026600800800260660046062002a666050604a60546ea80044c8c8c8c94ccc0c0c0cc0084c926323300100100222533303200114984c8cc00c00cc0d8008c8c8dd718198011bae30310013034001163756606200260620046eb4c0bc004c0acdd50008b192999814181098151baa0011302e302b37540022a660529201134e6f7420616e20696e6c696e6520646174756d00163014302a3754603860546ea800458c0b0004c8cc0480188c008c070c0a8dd5000a999812981118139baa4c0103d8798000123300f3756603660526ea800402448cdc4240006660226eacc06cc0a4dd50009bae3017302937540126eb8c06cc0a4dd50049bae302a302737540022c6028604c6ea8c050c098dd5180c18131baa3029302637540022c660226eb0c0a0010054dd598139814181418140011bac3026001302600130213754004446e64c8c8ccc0040040112201002225333024002100113233300400430280035333021301e371a00426e600044cdc500119b8a00537300026e64dd718130011b98001300100122533301e00114bd7009980f980e1810000998010011810800a4909436f6c6c6563746f72003009301b375401e600a60366ea805c88c04cccc010008dd71805180e1baa001375c601c60386ea8004dc7a45002223253330193013301b37540022900009bad301f301c375400264a666032602660366ea8004530103d87a80001323300100137566040603a6ea8008894ccc07c004530103d87a80001323232533301e3371e00e6eb8c08000c4c038cc08cdd4000a5eb804cc014014008dd6981000118118011810800991980080080211299980f0008a6103d87a80001323232533301d3371e00e6eb8c07c00c4c034cc088dd3000a5eb804cc014014008dd5980f8011811001181000091191980080080191299980e0008a5eb804c8c94ccc068c0140084cc07c008cc0100100044cc010010004c080008c0780048c068c06cc06c004894ccc050ccc0500052825115330150021001100122323300100100322533301900114c103d87a80001323253330173375e601060346ea80080144c01ccc0700092f5c0266008008002603a00460360026e9520002301600130103754012602660206ea800458c004c03cdd5001918091809800980818069baa00114984d958c94ccc024c01800454ccc034c030dd50020a4c2c2a66601260060022a66601a60186ea8010526161533300930020011533300d300c37540082930b0b18051baa003370e90021b8748008c94ccc014c008c01c00454ccc024c020004526161637540046e1d20005734ae7155ceaab9e5573eae815d0aba21"
164
250
  };
165
251
 
252
+ // src/helpers/lucid-utils.ts
253
+ import {
254
+ addAssets,
255
+ credentialToAddress as credentialToAddress2,
256
+ paymentCredentialOf,
257
+ scriptHashToCredential,
258
+ stakeCredentialOf
259
+ } from "@lucid-evolution/lucid";
260
+ function getInlineDatumOrThrow(utxo) {
261
+ if (utxo.datum != null) {
262
+ return utxo.datum;
263
+ }
264
+ throw new Error(
265
+ "Expected an inline datum for OutRef: " + JSON.stringify({
266
+ txHash: utxo.txHash,
267
+ outputIndex: utxo.outputIndex
268
+ })
269
+ );
270
+ }
271
+ async function addrDetails(lucid) {
272
+ const addr = await lucid.wallet().address();
273
+ return [paymentCredentialOf(addr), stakeCredentialOf(addr)];
274
+ }
275
+ function createScriptAddress(network, scriptHash, stakeCredential) {
276
+ return credentialToAddress2(
277
+ network,
278
+ scriptHashToCredential(scriptHash),
279
+ stakeCredential
280
+ );
281
+ }
282
+ async function scriptRef(ref, lucid) {
283
+ const utxos = await lucid.utxosByOutRef([
284
+ { txHash: ref.input.transactionId, outputIndex: ref.input.index }
285
+ ]);
286
+ if (utxos.length === 0) throw Error("Unable to locate script ref.");
287
+ return utxos[0];
288
+ }
289
+ function balance(utxos) {
290
+ return utxos.reduce((acc, utxo) => addAssets(acc, utxo.assets), {});
291
+ }
292
+
293
+ // src/helpers/helpers.ts
294
+ import * as fs from "fs";
295
+ import { match as match2, P as P2 } from "ts-pattern";
296
+ function matchSingle(xs, mkErr) {
297
+ return match2(xs).with([P2.select()], (res) => res).otherwise(() => {
298
+ throw mkErr(xs);
299
+ });
300
+ }
301
+ function calculateFeeFromPercentage(percent, amount) {
302
+ if (amount <= 0n) return 0n;
303
+ const a = amount * percent / 1000000n;
304
+ const b = BigInt(1e8);
305
+ return a * 1000000n / b;
306
+ }
307
+ function loadSystemParamsFromFile(file) {
308
+ return JSON.parse(fs.readFileSync(file, "utf-8"));
309
+ }
310
+ function loadSystemParamsFromUrl(url) {
311
+ return fetch(url).then((res) => res.json()).then((data) => data);
312
+ }
313
+ var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
314
+
166
315
  // src/contracts/collector.ts
167
316
  var CollectorContract = class _CollectorContract {
168
317
  static async feeTx(fee, lucid, params, tx, collectorRef) {
169
- const collectorUtxo = collectorRef ? getRandomElement(await lucid.utxosByOutRef([collectorRef])) : getRandomElement(await lucid.utxosAt(
170
- _CollectorContract.address(params.collectorParams, lucid)
171
- ));
318
+ const collectorUtxo = collectorRef ? getRandomElement(await lucid.utxosByOutRef([collectorRef])) : getRandomElement(
319
+ await lucid.utxosAt(
320
+ _CollectorContract.address(params.collectorParams, lucid)
321
+ )
322
+ );
172
323
  const collectorScriptRefUtxo = await _CollectorContract.scriptRef(
173
324
  params.scriptReferences,
174
325
  lucid
175
326
  );
176
- tx.collectFrom([collectorUtxo], Data3.to(new Constr3(0, []))).pay.ToContract(
327
+ tx.collectFrom([collectorUtxo], Data5.to(new Constr(0, []))).pay.ToContract(
177
328
  collectorUtxo.address,
178
- { kind: "inline", value: Data3.to(new Constr3(0, [])) },
329
+ { kind: "inline", value: Data5.to(new Constr(0, [])) },
179
330
  {
180
331
  ...collectorUtxo.assets,
181
- lovelace: collectorUtxo.assets["lovelace"] + fee
332
+ lovelace: collectorUtxo.assets.lovelace + fee
182
333
  }
183
334
  ).readFrom([collectorScriptRefUtxo]);
184
335
  }
@@ -186,147 +337,47 @@ var CollectorContract = class _CollectorContract {
186
337
  static validator(params) {
187
338
  return {
188
339
  type: "PlutusV2",
189
- script: applyParamsToScript2(_collectorValidator.cborHex, [
190
- new Constr3(0, [
191
- new Constr3(0, [
340
+ script: applyParamsToScript(_collectorValidator.cborHex, [
341
+ new Constr(0, [
342
+ new Constr(0, [
192
343
  params.stakingManagerNFT[0].unCurrencySymbol,
193
- fromText3(params.stakingManagerNFT[1].unTokenName)
344
+ fromText2(params.stakingManagerNFT[1].unTokenName)
194
345
  ]),
195
- new Constr3(0, [
346
+ new Constr(0, [
196
347
  params.stakingToken[0].unCurrencySymbol,
197
- fromText3(params.stakingToken[1].unTokenName)
348
+ fromText2(params.stakingToken[1].unTokenName)
198
349
  ]),
199
- new Constr3(0, [
350
+ new Constr(0, [
200
351
  params.versionRecordToken[0].unCurrencySymbol,
201
- fromText3(params.versionRecordToken[1].unTokenName)
352
+ fromText2(params.versionRecordToken[1].unTokenName)
202
353
  ])
203
354
  ])
204
355
  ])
205
356
  };
206
357
  }
207
358
  static validatorHash(params) {
208
- return validatorToScriptHash2(_CollectorContract.validator(params));
359
+ return validatorToScriptHash(_CollectorContract.validator(params));
209
360
  }
210
361
  static address(params, lucid) {
211
362
  const network = lucid.config().network;
212
363
  if (!network) {
213
364
  throw new Error("Network configuration is undefined");
214
365
  }
215
- return validatorToAddress2(network, _CollectorContract.validator(params));
366
+ return validatorToAddress(network, _CollectorContract.validator(params));
216
367
  }
217
368
  static async scriptRef(params, lucid) {
218
369
  return scriptRef(params.collectorValidatorRef, lucid);
219
370
  }
220
371
  };
221
372
 
222
- // src/contracts/interest-oracle.ts
223
- import { Constr as Constr4, Data as Data4 } from "@lucid-evolution/lucid";
224
-
225
- // src/helpers/time-helpers.ts
226
- var oneHour = 3600000n;
227
- var oneDay = 86400000n;
228
- var oneYear = 31536000000n;
229
-
230
- // src/contracts/interest-oracle.ts
231
- var unitaryInterestPrecision = 1000000000000000000n;
232
- var decimalUnit = 1000000n;
233
- var InterestOracleContract = class _InterestOracleContract {
234
- static decodeInterestOracleDatum(datum) {
235
- const oracleDatum = Data4.from(datum);
236
- if (oracleDatum.index != 0 || oracleDatum.fields.length !== 3 || oracleDatum.fields[1].index !== 0)
237
- throw "Invalid Interest Oracle Datum provided.";
238
- return {
239
- unitaryInterest: oracleDatum.fields[0],
240
- interestRate: oracleDatum.fields[1].fields[0],
241
- lastUpdated: oracleDatum.fields[2]
242
- };
243
- }
244
- static encodeInterestOracleDatum(datum) {
245
- return Data4.to(
246
- new Constr4(0, [
247
- datum.unitaryInterest,
248
- new Constr4(0, [datum.interestRate]),
249
- datum.lastUpdated
250
- ])
251
- );
252
- }
253
- static calculateUnitaryInterestSinceOracleLastUpdated(now, oracleDatum) {
254
- return _InterestOracleContract.calculateUnitaryInterest(now - oracleDatum.lastUpdated, oracleDatum.interestRate);
255
- }
256
- static calculateUnitaryInterest(timePeriod, interestRate) {
257
- return timePeriod * interestRate * unitaryInterestPrecision / oneYear / decimalUnit;
258
- }
259
- static calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, interestLastSettled, interestOracleDatum) {
260
- if (interestOracleDatum.unitaryInterest >= unitaryInterestSnapshot) {
261
- const interestFromPreviousRates = (interestOracleDatum.unitaryInterest - unitaryInterestSnapshot) * mintedAmount / unitaryInterestPrecision;
262
- const lastRateInterest = (now - interestOracleDatum.lastUpdated) * interestOracleDatum.interestRate * mintedAmount / oneYear / decimalUnit;
263
- return interestFromPreviousRates + lastRateInterest;
264
- } else {
265
- return (now - interestLastSettled) * interestOracleDatum.interestRate * mintedAmount / oneYear / decimalUnit;
266
- }
267
- }
268
- };
269
-
270
- // src/contracts/gov.ts
271
- import { Constr as Constr5, Data as Data5 } from "@lucid-evolution/lucid";
272
- var GovContract = class {
273
- static decodeGovDatum(datum) {
274
- const d = Data5.from(datum);
275
- if (d.index !== 0 || d.fields.length !== 6 || d.fields[1].fields.length !== 10)
276
- throw "Invalid GovDatum found";
277
- return {
278
- currentProposal: d.fields[0],
279
- protocolParams: {
280
- proposalDeposit: d.fields[1].fields[0],
281
- votingPeriod: d.fields[1].fields[1],
282
- effectiveDelay: d.fields[1].fields[2],
283
- expirationPeriod: d.fields[1].fields[3],
284
- collateralFeePercentage: d.fields[1].fields[4].fields[0],
285
- proposingPeriod: d.fields[1].fields[5],
286
- totalShards: d.fields[1].fields[6],
287
- minimumQuorum: d.fields[1].fields[7],
288
- maxTreasuryLovelaceSpend: d.fields[1].fields[8],
289
- maxTreasuryIndySpend: d.fields[1].fields[9]
290
- },
291
- currentVersion: d.fields[2],
292
- iassetsCount: d.fields[3],
293
- activeProposals: d.fields[4],
294
- treasuryIndyWithdrawnAmt: d.fields[5]
295
- };
296
- }
297
- static encodeGovDatum(datum) {
298
- return Data5.to(
299
- new Constr5(0, [
300
- datum.currentProposal,
301
- new Constr5(0, [
302
- datum.protocolParams.proposalDeposit,
303
- datum.protocolParams.votingPeriod,
304
- datum.protocolParams.effectiveDelay,
305
- datum.protocolParams.expirationPeriod,
306
- new Constr5(0, [datum.protocolParams.collateralFeePercentage]),
307
- datum.protocolParams.proposingPeriod,
308
- datum.protocolParams.totalShards,
309
- datum.protocolParams.minimumQuorum,
310
- datum.protocolParams.maxTreasuryLovelaceSpend,
311
- datum.protocolParams.maxTreasuryIndySpend
312
- ]),
313
- datum.currentVersion,
314
- datum.iassetsCount,
315
- datum.activeProposals,
316
- datum.treasuryIndyWithdrawnAmt
317
- ])
318
- );
319
- }
320
- };
321
-
322
373
  // src/contracts/treasury.ts
323
374
  import {
324
- applyParamsToScript as applyParamsToScript3,
325
- Constr as Constr6,
375
+ applyParamsToScript as applyParamsToScript2,
376
+ Constr as Constr2,
326
377
  Data as Data6,
327
- fromText as fromText4,
328
- validatorToAddress as validatorToAddress3,
329
- validatorToScriptHash as validatorToScriptHash3
378
+ fromText as fromText3,
379
+ validatorToAddress as validatorToAddress2,
380
+ validatorToScriptHash as validatorToScriptHash2
330
381
  } from "@lucid-evolution/lucid";
331
382
 
332
383
  // src/scripts/treasury-validator.ts
@@ -339,14 +390,16 @@ var _treasuryValidator = {
339
390
  // src/contracts/treasury.ts
340
391
  var TreasuryContract = class _TreasuryContract {
341
392
  static async feeTx(fee, lucid, params, tx, treasuryRef) {
342
- const treasuryUtxo = treasuryRef ? getRandomElement(await lucid.utxosByOutRef([treasuryRef])) : getRandomElement(await lucid.utxosAt(
343
- _TreasuryContract.address(params.treasuryParams, lucid)
344
- ));
393
+ const treasuryUtxo = treasuryRef ? getRandomElement(await lucid.utxosByOutRef([treasuryRef])) : getRandomElement(
394
+ await lucid.utxosAt(
395
+ _TreasuryContract.address(params.treasuryParams, lucid)
396
+ )
397
+ );
345
398
  const treasuryScriptRefUtxo = await _TreasuryContract.scriptRef(
346
399
  params.scriptReferences,
347
400
  lucid
348
401
  );
349
- tx.collectFrom([treasuryUtxo], Data6.to(new Constr6(4, []))).pay.ToContract(
402
+ tx.collectFrom([treasuryUtxo], Data6.to(new Constr2(4, []))).pay.ToContract(
350
403
  treasuryUtxo.address,
351
404
  { kind: "inline", value: treasuryUtxo.datum || "" },
352
405
  {
@@ -359,57 +412,49 @@ var TreasuryContract = class _TreasuryContract {
359
412
  static validator(params) {
360
413
  return {
361
414
  type: "PlutusV2",
362
- script: applyParamsToScript3(_treasuryValidator.cborHex, [
363
- new Constr6(0, [
364
- new Constr6(0, [
415
+ script: applyParamsToScript2(_treasuryValidator.cborHex, [
416
+ new Constr2(0, [
417
+ new Constr2(0, [
365
418
  params.upgradeToken[0].unCurrencySymbol,
366
- fromText4(params.upgradeToken[1].unTokenName)
419
+ fromText3(params.upgradeToken[1].unTokenName)
367
420
  ]),
368
- new Constr6(0, [
421
+ new Constr2(0, [
369
422
  params.versionRecordToken[0].unCurrencySymbol,
370
- fromText4(params.versionRecordToken[1].unTokenName)
423
+ fromText3(params.versionRecordToken[1].unTokenName)
371
424
  ]),
372
- params.treasuryUtxosStakeCredential ? new Constr6(0, [
373
- new Constr6(0, [
374
- new Constr6(1, [
425
+ params.treasuryUtxosStakeCredential ? new Constr2(0, [
426
+ new Constr2(0, [
427
+ new Constr2(1, [
375
428
  params.treasuryUtxosStakeCredential.contents.contents
376
429
  ])
377
430
  ])
378
- ]) : new Constr6(1, [])
431
+ ]) : new Constr2(1, [])
379
432
  ])
380
433
  ])
381
434
  };
382
435
  }
383
436
  static validatorHash(params) {
384
- return validatorToScriptHash3(_TreasuryContract.validator(params));
437
+ return validatorToScriptHash2(_TreasuryContract.validator(params));
385
438
  }
386
439
  static address(params, lucid) {
387
440
  const network = lucid.config().network;
388
441
  if (!network) {
389
442
  throw new Error("Network configuration is undefined");
390
443
  }
391
- return validatorToAddress3(network, _TreasuryContract.validator(params), params.treasuryUtxosStakeCredential ? { type: "Script", hash: params.treasuryUtxosStakeCredential.contents.contents } : void 0);
444
+ return validatorToAddress2(
445
+ network,
446
+ _TreasuryContract.validator(params),
447
+ params.treasuryUtxosStakeCredential ? {
448
+ type: "Script",
449
+ hash: params.treasuryUtxosStakeCredential.contents.contents
450
+ } : void 0
451
+ );
392
452
  }
393
453
  static async scriptRef(params, lucid) {
394
454
  return scriptRef(params.treasuryValidatorRef, lucid);
395
455
  }
396
456
  };
397
457
 
398
- // src/helpers/helpers.ts
399
- import * as fs from "fs";
400
- function calculateFeeFromPercentage(percent, amount) {
401
- if (amount <= 0n) return 0n;
402
- const a = amount * percent / 1000000n;
403
- const b = BigInt(1e8);
404
- return a * 1000000n / b;
405
- }
406
- function loadSystemParamsFromFile(file) {
407
- return JSON.parse(fs.readFileSync(file, "utf-8"));
408
- }
409
- function loadSystemParamsFromUrl(url) {
410
- return fetch(url).then((res) => res.json()).then((data) => data);
411
- }
412
-
413
458
  // src/scripts/cdp-validator.ts
414
459
  var _cdpValidator = {
415
460
  type: "PlutusV2",
@@ -417,61 +462,215 @@ var _cdpValidator = {
417
462
  cborHex: "593a8e593a8b010000323232323232323222323232323232323223232323232322533301332323253330163011301837540022646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464a6464646660b660b008826464646464a6660c000c264646464646464a6660ce60c860d26ea80044c8c94ccc1a4c198c1acdd5000899192999835983418369baa001132323232325333074307700213232533307630790021325333073306e3075375400226464a6660f260f800426464646464646464a6660fa660c492010f4261642074782076616c6964697479003302f305930800137540d26605c66e04084dd6981a1840009baa07c337000426eb4c0d0c20004dd503e0a99983e9983124811942616420696e707574206265696e672076616c6964617465640030253065308001375401c2a6660fa660c492010e4d697865642076657273696f6e73003375e60ca6100026ea8058c194c20004dd518329840009baa305c30800137540182a6660fa660c49211754582069736e74207369676e6564206279206f776e657200330280690141533307d3306249010d4d696e742069732077726f6e67003375e6e98018dd319982e9bae305c30800137540f86eb8c170c20004dd500e80f8a99983e998312481104261642069417373657420696e707574003371e6eb8c194c20004dd50049bae305c308001375403a2a6660fa660c49210e42616420434450206f7574707574003333304a018304c33082010164bd70181219841009832198410098321984100983219841009ba90144bd701984100982e1840009baa01d33082013750002661040260c866104026ea0084cc20804dd419b80375a60ca6100026ea801ccc0ac08401d2f5c097ae04bd7025eb80cc124c16cc194c20004dd503e00126103d87980001533307d330624911357726f6e6720706169642074726561737572790033333047375860a06100026ea81a406cdd598231840009baa069375c608a6100026ea81f0dd6982e1840009baa0031533307d533307d00513232533307f33064490115556e646572636f6c6c61746572697a65642043445000333302f004003006302930820137540162660c89211757726f6e67207061696420746f20636f6c6c6563746f72003333304601a01d375660906104026ea81acdd718229841009baa07e3370066e00008004dd698339841009baa00514a06606c60886102026ea8028dd698331840809baa3303a30653308301375004097ae00053303533026019302930800137540f860aa03c2660c492011b57726f6e67207061696420636f6c6c6563746f7220696e74727374003333304401801b3756608c6100026ea81a4dd718219840009baa07c375a60ca6100026ea800c54ccc1f4cc189241164e6f6e706f736974697665206d696e74656420616d740030480011533307d3306249011a43616e2774206d696e742064656c69737465642069417373657400533307d533307d3078307f375460b86100026ea80245288a5014a2266e2407d20001330624911a636f6c6c61746572616c203c206d696e436f6c6c61746572616c00337126eb4c118c20004dd503e0010a5014a029405280a5014a029405280a5014a02940cdc01bad304f307f375403803c66e04cdc0181f9bab305a307e375460b460fc6ea8030070c0c0004c94ccc1ecc1180044cc0c4dd69831983f1baa3303700230623308001375000297ae000714c0106d8799f0000ff003333303701e00d375a609a60fa6ea80680380114ccc1e40044ccc0a0c160c1f0dd500280a982a983e1baa0651330373058307c375400a02aa6660f0608603429444cdc400ca400060b46eacc084c1e8dd50319981b0091824983c9baa002306d00116307a001307637540022c6066608a60ea6ea8c144c1d4dd50008b183b800999819006182198399baa06f4c0103d879800016307500133303000c3056307137540da98103d8798000375a60e660e80046eb4c1c8004c1b8dd50008b182398369baa00a375c60de60d86ea800458c140c1acdd5004182798351baa3046306a375460da60d46ea800458cc130010140dd6183598360011bac306a001306a002375860d000260c86ea8134c198c18cdd502f0a50375a60ca60cc0046eb4c190004c190008dd69831000982f1baa0501533305b3056044132533305c002132323232323232533306330603065375400226464a6660ca60c460ce6ea80044c8c94ccc19cc190c1a4dd50008991919191929998381839801099192999839183a801099192999838183598391baa0011323253330763079002132325333074330594910f4261642074782076616c696469747900330263050307737540c06604a66e04064dd69815983b9baa073337000326eb4c0acc1dcdd50398a99983a1982ca4811357726f6e672070616964207472656173757279003333303e3758608e60ee6ea8180058dd5981e983b9baa060375c607860ee6ea81ccdd69829983b9baa001153330743305949011942616420696e707574206265696e672076616c69646174656400301c305c307737540122a6660e8660b292010e4d697865642076657273696f6e73003375e02260b860ee6ea8c170c1dcdd51829983b9baa00715333074330594911754582069736e74207369676e6564206279206f776e6572003301f06000f15333074330594901154275726e65642076616c75652069732077726f6e67003375e6e98c15cdd5980f183b9baa060374c666608a609660a460b860ee6ea81ccdd71829983b9baa073375c60a660ee6ea8060c130dd69823983b9baa01813305949011457726f6e67207061696420636f6c6c6563746f72003333303b0130163756607a60ee6ea8180dd7181d183b9baa07333700660586603a028604060ee6ea81cccdc080318148009bad305c3077375400229405280a5014a0294052819299983a181f8008998151bad305c30773754660606606460a660ee6ea800c050c16ccc1e4dd4000a5eb8000c5300106d8799f0000ff003333303001800a375a608c60ec6ea805c02ccc0cc04cc118c1d8dd500118350008b183b80098399baa001163030304230723754609c60e46ea8008c0c8dd5982698389baa304d307137540062c60e600266605c018607e60de6ea81ad30103d879800016307100133302c00c3052306d37540d298103d8798000375a60de60e00046eb4c1b8004c1a8dd50008b182198349baa00a375c60d660d06ea800458c130c19cdd5004182598331baa304b30663754608460cc6ea8c1a4c198dd50008b198240020261bac30673068002375860cc00260cc0046eb0c190004c180dd50249831182f9baa05a14a06eb4c184c178dd502809919299982e9828823099299982f002099911919191919192999833183198341baa0011323253330683065306a375400226464a6660d460ce60d86ea80044c8c8c8c8c94ccc1ccc1d80084c8c94ccc1d4c1e00084c94ccc1c8c1b4c1d0dd500089919299983c183d801099191919191919191919191929998400099832a490f4261642074782076616c69646974790033032305c30830137540d86606266e0408cdd6981b9841809baa07f337000466eb4c0dcc20c04dd503f8a9998400099832a4811942616420696e707574206265696e672076616c696461746564003028306830830137540242a66610002660ca92010e4d697865642076657273696f6e73003375e60d06106026ea8068c1a0c20c04dd518341841809baa305f30830137540202a66610002660ca9211643522068617320746f20626520756e64657220524d5200333080013333030007375a60a66106026ea8084024c174c20c04dd5006a504a22a66610002660ca9211a43522068617320746f206265206174206c656173742031303025003333030007375a60a66106026ea8084024c19ccc21404dd401ca5eb8054ccc20004cc19524010d4d696e742069732077726f6e67003375e6e98028dd31998301bae305f30830137540fe6eb8c17cc20c04dd5010982c0028a9998400099832a4811242616420726564656d7074696f6e20616d7400533308001304b00513371200a00c294054ccc20004cc1952410e42616420434450206f7574707574003333304d01c304f330850101a4bd70181399842809833998428098339984280983399842809ba90184bd701984280982f9841809baa021330850137500066610a0260ce6610a026ea008ccc21404dd419b80375a60d06106026ea802ccc0b808c02d2f5c097ae04bd7025eb80cc130c178c1a0c20c04dd503f800a6103d87980001533308001330654911357726f6e672070616964207472656173757279003333304a375860a66106026ea81b007cdd598249841809baa06c375c60906106026ea81fcdd6982f9841809baa00815333080013306549011457726f6e67207061696420636f6c6c6563746f72003333304701c01f375660926106026ea81b0dd718231841809baa07f3370066e00dd698341841809baa008330383022308301375401a004a6661000200826eb4c088c20c04dd503f8a40002a66610002660ca92011a636f6c6c61746572616c203c206d696e436f6c6c61746572616c00337126eb4c124c20c04dd503f800899832a481164e6f6e706f736974697665206d696e74656420616d7400304b00314a029405280a5014a029405280a5014a0294052819b803370200c0026606e60906104026ea8030004dd698331840809baa3303a30653308301375000697ae0007337026eb4c140c20004dd500f00119b880010023053333040005375c60b460fc6ea81e8dd7182d183f1baa01c33223020330363302130633308101375060a86eb4c190c1fcdd51981b183199840809ba830370034bd70002a5eb80cc0d8cc0e0004c18ccc20404dd4181b80125eb80c18ccc20404dd401aa5eb80c18ccc20404dd419b81375a60c860fe6ea8cc0d8004c18ccc20404dd401aa5eb80dd69832183f9baa4c109d8799f1a000f4240ff004bd701bad304d307d375403660ae60fa6ea801ccdc0981e9bab3058307c375460b060f86ea802cc0b8004c94ccc1e4c1100044cc0bcdd69830983e1baa3303500230603307e375000297ae000614c106d8799f0000ff003333303501b00c375a609660f66ea806403400cccc098c158c1e8dd500200a1829983d1baa06330593756604060f26ea8188cc0d4048c120c1e0dd500118360008b183c800983a9baa00116303230443074375460a060e86ea800458c1d8004ccc0c4030c108c1c8dd5037260103d879800016307400133302f00c3055307037540d898103d8798000375a60e460e60046eb4c1c4004c1b4dd50008b182318361baa00a375c60dc60d66ea800458c13cc1a8dd5004182718349baa30453069375460d860d26ea800458cc12c01013cdd6183518358011bac30690013069002375860ce00260c66ea81308c194c198c198c198c198c198c198c198c198c198c198004c190c184dd502e0a50375a60c660c06ea81484c94ccc178c14411c4c94ccc17c0144cc88c8c8c8c94ccc194c188c19cdd5000899192999833983218349baa00113232323232533307030730021323253330723075002132533306f306a3071375400226464a6660ea60f000426464646464a6660ec660b69210f4261642074782076616c696469747900330283052307937540c46604e66e04060dd69816983c9baa075337000306eb4c0b4c1e4dd503a8a99983b1982da4811942616420696e707574206265696e672076616c69646174656400301e305e307937540162a6660ec660b692010e4d697865642076657273696f6e73003375e02260bc60f26ea8c178c1e4dd5182a983c9baa009153330763305b4911543445020697320616c72656164792066726f7a656e00533307630733078375460bc60f26ea80585288a50153330763305b4901104261642069417373657420696e707574003371e6eb8c178c1e4dd50031bae30553079375402c2a6660ec660b69210a43616e2774206d696e74003375e6e98c164dd59810183c9baa0624c101a000153330763305b4911a434450207374696c6c206f766572636f6c6c61746572697a6564003330763333026002375a609260f26ea8058010c064c1e4dd50032504a22660b692010e42616420434450206f757470757400333330433758609260f26ea8188c114cc1ecc174cc1ec044cc1ed30103d87a80004bd7025eb80c074cc1ecc174cc1ecc174cc1ed300103d87a80003307b30553079375402c660f6609260f26ea8058cc1ecc114cc1ecc154c1e4dd50019983d9ba8337000026eb4c178c1e4dd5001a5eb812f5c097ae04bd701bab30553079375460aa60f26ea802d30103d879800014a029405280a5014a029405281980b198169828983c1baa005375a60ba60f06ea8cc0c4c170cc1e8c120c1e0dd500aa5eb8000ccc0b4c144c1e0dd500280099b813038375660a660ee6ea8c14cc1dcdd500498148009919299983a98200008998159980b0011bad305d307837546606200660b8660f46ea00052f5c000a298106d8799f0000ff003333303101600b375a608e60ee6ea8050030cc0d0044c11cc1dcdd500219299983a19b89375a60b860ee6ea800520001480004c060004cc060c168cc1e0dd41817181b9bab30523076375460a460ec6ea80212f5c06605e60b4660f06ea0c0b8c12cdd69823183b1baa0134bd70000998181828983a9baa00200f3069001163076001307237540022c605e608260e26ea8c134c1c4dd50008b1839800999817004981f98379baa06b4c103d879800016307100133302c0083052306d37540d298103d8798000375a60de60e00046eb4c1b8004c1a8dd50008b182198349baa006304d30683754609a60d06ea8c110c1a0dd5183598341baa001163304a00204e375860d260d40046eb0c1a0004c190dd502691299983099b88001002100110023065306237540ba2940dd6983218309baa053132533305f30510481533305f00513322325333062305f30643754002264646464a6660d460da6eb0c1a00084c8c8c8c8c8c8c94ccc1b4cc14924011a4174206c656173742031206f746865722043445020696e7075740033306d533307100814a22941282511533306d3305249012743445020696e70757473206d75737420757365204d65726765417578696c696172792072646d72003300e008232323375e00466e95200a3307505a4bd70182f8009981e182b18389baa0013756606e60e26ea816854ccc1b4cc14924012943445020696e70757473206d7573742062652066726f7a656e20776974682073616d65206173736574003300e00a232325333070306d3072375400426464a6660e4602860f0004266e3c0040485281bae307730780013073375460ec60e66ea800852818330009817982098389baa304d307137540022a6660da660a4921074e6f206d696e74003375e6e98c140dd5980b98381baa0594c101a00013305249010e42616420434450206f7574707574003333303a3758608060e06ea8164c0f0cc1c8c150cc1c802ccc1c930103d87a80004bd7025eb80c050cc1c8c150cc1c8c150cc1c9300103d87a800033072375201a660e46ea0010cc1c8c0f0cc1c8dd4001198391ba80014bd7025eb812f5c097ae00064c0103d87a800014a029405280a50375a60e460e60046eb4c1c4004c1c4008dd6983780098378011bab306d001323300100100422533306c00114bd70901a00081010000810100008101000009991191919191919192999838983718399baa001132325333077307a0021533307330703075375400226464646464646464a6660fe610402004264a6660f860ee60fc6ea80084c8c8c8c94ccc21004c21c040084cc21404dd31982b00b1bab305f308301375460be6106026ea8060cc21404dd419b800140083308501375066e0004800ccc21404dd419b800110014bd700b1bad308501001308501002375a61060200260fe6ea800858c1d401c58c20004004c20004008dd6983f000983f0011bae307c001307c002307a001307637540022c2c60f000260e86ea800458c0c4c10cc1ccdd5182798399baa008375a60ea60ec0046eb4c1d0004c1d0008dd6983900098390011bab3070001306e00133002002306f00116375860d0002646600200200444a6660d4002297bdb180101800001018000132323232533306a30123052306d3754008266ec0dd3998378020011ba70011337606e9c008dd3998378020009bac306c002375860d40026600600660dc00460d800266604a6eb0c12cc198dd5027982598331baa0624c0103d87a8000304a30653754609460ca6ea8c104c194dd5183418329baa00116330473758609260c86ea813412c88c8cc00400400c894ccc19c0045288992999832180218350010998018018008a50306a001375c60ca60cc60c46ea8c194c188dd502e8a501533305f30500481325333060006132325333062305f30643754002264a6660c6660909212b546865206d61696e206d65726765205554584f206973207573696e67204d65726765434450732072646d720032323375e004980103d87d80003054001330310043756605860cc6ea813c4cc1212401256d65726765205554584f20636f6d65732066726f6d207468652073616d65207363726970740033038003253330643375e00a609860ce6ea80044cdd7982618339baa304c30673754608660ce6ea80040085280a50304a30653754609460ca6ea8c104c194dd5183418329baa001163304700104b375860cc60c66ea8130528183298311baa05413253330603370e90060248a99983000309991191919192999833183198341baa0011323253330683063306a375400226464646464a6660e260e80042646464a6660e860ee004264646464a6660e8660b29211942616420696e707574206265696e672076616c69646174656400301c305c307737540102a6660e8660b292011357726f6e672070616964207472656173757279003333303e3758608e60ee6ea8180044dd5981e983b9baa060375c607860ee6ea81cc02c54ccc1d0cc1652411457726f6e67207061696420636f6c6c6563746f72003333303b0100113756607a60ee6ea8180dd7181d183b9baa07300a153330743305949116434450206e6565647320746f2062652066726f7a656e003016305c307737540262a6660e8660b292010e57726f6e6720535020746f6b656e0033037375660a660ee6ea8c14cc1dcdd50039828983b9baa073153330740021323253330763305b49010e42616420434450206f7574707574003333304301230453307b0104bd70180e9983d982e9983d982e9983d982f183c9baa0153307b30553079375402a660f66ea0cdc01bad30493079375402a00a660f6980106d87a9f0000ff004bd7025eb812f5c066084006609c00498103d8798000153330763305b49113426164205350206f75747075742076616c7565003375e60aa60f26ea801cdd31999823998210008011bae3055307937540ea6eb8c154c1e4dd500a80289982da491b4d757374206275726e20616c6c206941737365747320696e205350003375e6e98018dd318269980b000982e9983d982a983c9baa0753307b30553079375402a97ae014a02940dd5982a183c1baa30543078375401066e0ccdc1181c00098260019bad3047307737540262a6660e8660b2921374d757374206275726e20616c6c206d696e74656420694173736574732026206175746820746f6b656e7320696e2063647020696e707574003375e6e98010dd3199982298259980a000982e183b9baa073375c60a660ee6ea81ccdd71829983b9baa013304c375a608e60ee6ea804c4cc16524113426164205350206f75747075742076616c7565003375e60a660ee6ea8014dd31999822998201bab30533077375460a660ee6ea801cc0e0004dd71829983b9baa073375c60a660ee6ea804cc130dd69823983b9baa01314a029405280a5014a02940cc0fccc0fcdd59829183b1baa30523076375400e6096014609601266e20c128004dd69822983a9baa011333036001375c60a060e86ea81c0dd71828183a1baa01030533756603460e66ea817058c1d4004cc108028c100c0f4cc1ccc154cc1ccc0f4cc1ccc128c1c4dd5036a5eb80cc1cd30103d87a80004bd7025eb80c94ccc1c800454cc1bd2401144f6e6520535020696e70757420616c6c6f776564001615333072307500113074001153306f4901144f6e6520535020696e70757420616c6c6f77656400163303d00a303c330723049307037540d897ae016307200133302d0083053306e37540d4980103d87a8000375a60e060e20046eb4c1bc004c1acdd50008b182218351baa006304e30693754608a60d26ea8c1b0c1a4dd50008b198258010279bac306a306b306b002375860d200260ca6ea813888ccc108dd7182518329baa001375c608260ca6ea8004cc00c008004c198c18cdd502f0a50153330603370e90070248a999830182d98311baa05e132533306133046491125370656e642031207570677261646520746b00305c332232330010010032253330690011480004cdc0198010011836000998031bab304430683754608860d06ea8c1ac00400cdd6182498321baa04d3004306437540c026608c921354d757374206275726e207570677261646520746b2c206f7074696f6e616c6c79206d696e74206941737365742026206974732053500053330613375e6e98004dd3181c181f980218321baa06014a2266ebcdd30009ba63303733037303f303e306437540c0607e606860c86ea8180c0e0c0fcc010c190dd50300a5030433756601460c66ea81305280999919191119191919192999835183398361baa001132533306b3066306d37540022646464a6660e460ea0042646464a6660e260dc60e66ea80044cc158cc03ccc1d8dd49b984901084d697373696e6720003307637526e60038cc1d8dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd70249003301e30103054009375c60ee60e86ea800454cc1c8cc03ccc1d8dd49b98491084d697373696e6720003307637526e60038cc1d8dd49b9849010d20757067726164652070617468004bd702490016325333071306c30733754002298103d87a8000130583307637526eb8c1d0c8cdd8183c000983c183c8009bac30773074375400297ae03233001001375660a060e86ea800c894ccc1d80045300103d87a80001323253330743371e6eb8c1d80080244c16ccc1e4dd39983c983b0011983c983b80125eb812f5c026600800800260f400460f0002a6660de60d860e26ea80044c8c8c8c94ccc1dcc1e80084c926323300100100222533307900114984c8cc00c00cc1f4008c8c8dd7183d0011bae3078001307b00116375660f000260f00046eb4c1d8004c1c8dd50008b1817982098389baa304d307137540022c60e600266605c00a01098103d8798000375c60e260dc6ea800458c148c1b4dd5182918369baa3049306d375460e060da6ea800458cc13cdd618378020299bab306e306f306f306f002375860da00260da00260d06ea814488dcc9919199800800802244100222533306c0021001132333004004307000353330693066371a00426e600044cdc500119b8a00537300026e64dd718370011b98001300100122533306600114bd7009983398321834000998010011834800a490343445000300a306337540be4466604c0046eb8c124c190dd50009bae3040306437540024a6660be60b860c26ea80045280a512306430653065306530653065001232533305e3371060320026eb4c118c184dd5001099b80001480084004cdc19bad304530603754002904044bd111822198311ba8337006eb4c114c180dd50011bad30453060375400297ae03057305c37540b06e952004375e08444600660b86ea8c0e0c170dd51919299982f983100109919001299982e182c982f1baa0011323232323232323232323232533306c306f0021324994ccc1a0c194c1a8dd50048991919191919191919191919191919191919191929998400098418080109924c60ea0162c6eb4c20404004c20404008dd6983f800983f8011bad307d001307d002375a60f600260f60046eb4c1e4004c1e4008c1dc004c1dc008dd6983a800983a8011bad30730013073002375a60e200260e20046eb4c1bc004c1acdd50048b0b1bad306d001306d002375a60d600260d60046eb4c1a4004c1a4008dd698338009833801183280098328011bad3063001305f37540022c6038605c60bc6ea8c0e8c178dd50008b183000099980d801000a60103d87980002305d305e305e305e305e00122330043758600660b46ea80080048c16cc170c170c170c170c170c170c170c17000488c8cc00400400c894ccc16c004528099299982c19b8f375c60bc00400829444cc00c00c004c178004894ccc150cdc41bad302730573754002004266e0ccdc199b823370466e04008dd69813982b9baa001375a607860ae6ea8c0ccc15cdd5000a41010141ede959b7c03690405844fdf500a410112f42a660aa921254d75737420686f6c643a206e6f77203e206c61737420696e7465726573742075706461746500162225333054305130563754006260b460ae6ea800c4c94ccc154c94ccc158c144c160dd5000899b89375a606a60b26ea8008dd6982e182c9baa0011533057490124496e636f7272656374207472616e73616374696f6e2076616c69646974792072616e67650016303d30583754606860b06ea800854cc1592401174f7261636c652063616e2774206265206578706972656400161303d305837540026602600460b460ae6ea800c8888cdc49bad303c3057375466020660200026076660b26ea0c03c00d2f5c00046eb4c0f0c15cdd519808181d9982c9ba8300f0044bd70181d9982c9ba800d4bd7011181c1982b181c1982b18101982b1ba80024bd701982b199828a514c103d87a80004c0103d87980004bd701982b181c1982b18101982b1ba80014bd701982b199828a514c0103d87a80004c0103d87980004bd7025eb8088c8c94ccc148c94ccc14cc11c0045288a99982998270008a5114a060a86ea8cc014c0e8c154dd5001181d182a9baa0011325333053305000114a22a6660a6609c0022944528182a1baa33005303130553754004606260aa6ea8004528180280118020011119299982818268008a999828182698291baa00214c103d87a800014c103d879800015333050304400115333050304430523754004298103d87a800014c103d87b8000132325333052304d001132533305333710006002298103d879800015333053337100020062980103d87b800014c103d87a8000375a60b060aa6ea801054ccc148c13c004530103d87b800014c103d8798000305337540066eb4c158c14cdd500198289baa002230343305232533304e304930503754002264a66609e64a6660a860a60022a6660a0609660a4002294454ccc140c134c1480045280b0b1baa302e30523754606e60a46ea800c4c078cc150dd4000a5eb804c078cc150dd419b80001480092f5c06eb4c150c144dd50008800981a98281baa303530503754002660a464a66609c609260a06ea80044c94ccc13cc94ccc150c14c00454ccc140c12cc1480045288a999828182698290008a5016163754605c60a46ea8c0b8c148dd50018980f1982a1ba80014bd700980f1982a1ba8337000029000a5eb80dd6982a18289baa0011001303530503754605860a06ea80052f5c0466e00dd6981a18279baa001375a6056609e6ea800488c8c0d0cc148dd4000998291ba83370200600297ae0330043003304f3754002004460a060a260a260a260a260a260a260a260a260a260a260a200244a66609466e2400520001480004dd6981918269baa330043300630313304f375000297ae000230313304f375000697ae03002483200488c0bccc134dd419b833003375a606060966ea8008dd6981818259baa0014bd701b824820225e888c0b4cc12cdd419b83337046eb4c0b8c124dd50011bad302e30493754002904044bd25eb80888894ccc120cdc48021bad3030304b37540022a66609066e20dd6980d98259baa00100513370066e0ccdc119b81375a606060966ea800401000d208080a0f6f4acdbe01b3370666e0ccdc119b823370200a6eb4c06cc12cdd50009bad3030304b3754604e60966ea800400d2080b089fbea014820225e854cc1252401254d75737420686f6c643a206e6f77203e206c61737420696e746572657374207570646174650016153330483371000400a266e0ccdc199b823370466e04014008dd6981818259baa3027304b375400200690405844fdf500a410112f42a66092921264d75737420686f6c643a206e6f77203e20696e746572657374206c61737420736574746c6564001622533304430413046375400426094608e6ea80084c0b0c11cdd519801800982518239baa0022232320025333044304130463754002264646464a666098609e0042649318208018b1bad304d001304d002304b001304737540022c6008602c608c6ea8c088c118dd51929998240008a99822a492145787065637465642065786163746c79206f6e65206f7261636c6520696e707574001615333048304b0011304a001153304549012145787065637465642065786163746c79206f6e65206f7261636c6520696e7075740016333005002304930463754002980103d879800022323200253330433040304537540022646464646464a66609a60a00042649318210018b1bad304e001304e002304c001304c002375a6094002608c6ea800458c00cc054c114dd5181098229baa325333047001153304449012a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e707574001615333047304a00113049001153304449012a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e70757400163330040020014c0103d8798000253330403034304237540022608c60866ea800454cc1052401134e6f7420616e20696e6c696e6520646174756d0016222323301600423002302230463754002a666082607c60866ea800448cc014dd5981098229baa00100312300d33300737566042608a6ea8004dd7181518229baa003375c6042608a6ea800c88c0e8ccc010008dd7181398211baa001375c603c60846ea80048ccc0080052210048810022232533303f303a304137540022900009bad30453042375400264a66607e607460826ea8004530103d87a8000132330010013756608c60866ea8008894ccc114004530103d87a8000132323253330443371e00e6eb8c11800c4c0accc124dd4000a5eb804cc014014008dd698230011824801182380099198008008021129998220008a6103d87a8000132323253330433371e00e6eb8c11400c4c0a8cc120dd3000a5eb804cc014014008dd5982280118240011823000918209821182118211821182118210009111119299981f9805001099299982019191811801192999821181f8008a99982318229baa00214985854ccc108c0f400454ccc118c114dd50010a4c2c2a666084606c0022a66608c608a6ea80085261616304337540026601c605060866ea80040144ccccc03401cc03ccc114c09ccc114008cc115300103d87a80004bd7025eb8130107d87b9fd87980ff003300c3756603e60866ea8c07cc10cdd5000801a60103d879800014a064a6660880022a66082921284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400161533304430470011304600115330414901284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400163300f00500114a2601a660866ea40092f5c04607e6080608060806080608060806080608060806080608060800024607c607e607e607e607e607e607e607e607e607e0024444464a666078600e004264a66607a646466ebc00930103d87d800032533303f303c00115333043304237540042930b0a99981f981d0008a99982198211baa00214985854ccc0fcc0cc00454ccc10cc108dd50010a4c2c2a66607e60640022a66608660846ea8008526161533303f303100115333043304237540042930b0a99981f98180008a99982198211baa00214985858c100dd500099805981298201baa00100513333300a007302433042302530403754604a60806ea8c070c100dd5000a5eb8130107d87b9fd87980ff00330093756603860806ea8c070c100dd5000801a60103d879800014a064a6660820022a6607c921274d757374207370656e64203120696e7075742066726f6d20747265617375727920736372697074001615333041304400113043001153303e4901274d757374207370656e64203120696e7075742066726f6d2074726561737572792073637269707400163300c00500114a26014660806ea40092f5c06e212000223333007002488100488100001222223300d3300c005300a004253330393375e601860786ea80040104c94ccc0f80045288a99981f18208008991919299981e98109bae30430031533303d30210011533303d303a303f375400c2a66607a66e25200000213371200490404df7010a5013371290000010a5014a06eb8c108c10c008dd69820982118210009bac304000114a06466002002660206eacc064c0f4dd5001180880211299981f8008a5eb804c8ccc888c8cc00400400c894ccc114004400c4c8cc11cdd3998239ba90063304737526eb8c110004cc11cdd41bad30450014bd7019801801982480118238009bae303e0013756607e0026600600660860046082002294088c94ccc0d4c0c8c0dcdd50008981d981c1baa001153303649117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533303b00114c0103d87a80001323232533303a3375e00c6078006260426607e00297ae0133005005002303c002303f002303d0013003330390024bd701ba54800888cc0180088cdd7980d981b1baa301b303637546024606c6ea800400888894ccc0ccc0c000440104ccccc03401000cc8c8008c8cc004004008894ccc0e8004526132533303b00114984c8c94ccc0e4c0d8c0ecdd51980d9bae303b303f004375c607600426600a00a6607c0040022a66074921326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016303f002303d001303d00133038337606ea4008dd4000a5eb7bdb180888c94ccc0dcc040004530103d87a80001301e3303c374c00297ae03333301100100500422232533303a303700114c103d87a8000130213303f375000297ae03370000200403002a4a66605e605860626ea80044c88cdd7980c981a1baa301930343754002004606a60646ea80044c88cdd7980c981a1baa00100230353032375400246068606a606a00244646600200200644a666068002297ae01323253330323005002133037002330040040011330040040013038002303600122323300100100322533303300114a0264a6660606008606c00429444cc00c00c004c0d800488c8ccc00400400c0088894ccc0cc00840044c8ccc010010c0dc00cccccc028008dd718190009bab3033001222325333034300d00114c0103d87a80001301b33039374c00297ae032333001001003002222533303a0021001132333004004303e00333333012002375c60720026eb4c0e8004888c94ccc0ecc0e00045300103d87a80001302233040375000297ae0337000040020326078004024606a0044646600200200444a666060002297adef6c6013233032337606ea4dd718178009ba632330010013756606200444a666066002297adef6c6013233035337606ea4dd718190009ba83008375a606600266006006606e004606a00266006006606800460640026e0520002533302c00114a2294088888c8cc004004018894ccc0c40044cc0c8cdd81ba9006374c00a97adef6c60132323232533303130123300700a002133036337606ea4028dd30048028a99981899b8f00a0021325333032302f3034375400226606e66ec0dd4805981c181a9baa001004100433300800a009001133036337606ea4008dd3000998030030019bab3033003375c6062004606a004606600244444646600200200c44a66606000226606266ec0dd48031ba80054bd6f7b630099191919299981818089980380500109981a99bb037520146ea002401454ccc0c0cdc78050010992999818981718199baa001133036337606ea402cc0dcc0d0dd5000802080219980400500480089981a99bb037520046ea0004cc01801800cdd698190019bae3030002303400230320012302b302c302c302c302c302c302c302c0012302a302b302b302b0012333003375c6016604c6ea8004dd7180118131baa001480088c0a0c0a40048894ccc08cc08000452f5bded8c0264646600200297adef6c6022533302a00113302b337606ea4018dd3001a5eb7bdb1804c8c8c8c94ccc0a8c02ccc0300280084cc0bccdd81ba900a374c00e00a2a66605466e3c0280084cc0bccdd81ba900a374c00e00626605e66ec0dd48011ba600133006006003375660580066eb8c0a8008c0b8008c0b0004c8cc0040052f5bded8c044a66605200226605466ec0dd48021ba80034bd6f7b630099191919299981498051980580400109981719bb037520106ea001c01454ccc0a4cdc780400109981719bb037520106ea001c00c4cc0b8cdd81ba900237500026600c00c0066eb4c0ac00cdd71814801181680118158009baf4c103d879800022533302033720004002298103d8798000153330203371e0040022980103d87a800014c103d87b80002323300100100222533302400114bd6f7b63009919191929998121804001080189981499bb037520046e98004cc01801800cdd598130019bae302400230280023026001371e9110022533301d33301d0014a094454cc0780084004400488c8cc00400400c894ccc0880045300103d87a80001323253330203375e601060466ea80080144c01ccc0940092f5c0266008008002604c00460480026e9520002301f00130193754018603860326ea800458c06cc070008c068004c058dd50008a4c26cac600200c464a666024601e0022646464646464a666038603e0042930b1bad301d001301d002375a603600260360046eb4c064004c054dd50010a999809180680089919299980c180d8010a4c2c6eb4c064004c054dd50010a999809180300089919299980c180d8010a4c2c6eb4c064004c054dd50010a999809180280089919299980c180d8010a4c2c6eb4c064004c054dd50010a99980918020008a99980b180a9baa00214985854ccc048c00c0044c8c94ccc060c06c0084c9265333014301130163754002264646464a666038603e00426493299980c180a980d1baa00313232533301e3021002149858dd7180f800980d9baa0031616375a603a002603a0046036002602e6ea80045858c064004c054dd50010a99980919b874803000454ccc058c054dd50010a4c2c2a66602466e1d200e00115333016301537540042930b0a99980919b874804000454ccc058c054dd50010a4c2c2c60266ea8004dc3a40146e1d2008370e90031b8748010c0040208c94ccc02cc0200044c8c94ccc044c0500084c926533300d300a300f375400226464646464646464a6660326038004264649319299980b980a000899191919299980f98110010a4c2c6eb4c080004c080008dd6980f000980d1baa003153330173012001132323232533301f3022002149858dd6981000098100011bad301e001301a37540062c60306ea8008c03c01c58c068004c068008dd6980c000980c0011bae301600130160023014001301037540022c2c6024002601c6ea800854ccc02cc0180044c8c94ccc044c0500084c9263005001163012001300e37540042c60186ea800494ccc024c018c02cdd500089919191919191919191919191919191919191919191919191919191929998149816001099191919191919191919191924c6054018605001e604e020604c022604a02460480266046028604402a604202c604002e604403064a66604c604600226464a666058605e0042649318108008b181680098149baa01a15333026302100113232533302c302f0021324994ccc0a0c094c0a8dd5000899192999817181880109924c604c0022c605e00260566ea80045858c0b4004c0a4dd500d0b18139baa01916302a001302a002325333027302600115333023301e302500114a22a6660466040604a00229405858dd51814000981400118130009813001181200098120011811000981100118100009810001180f000980f001180e000980e001180d000980d001180c000980c001180b000980b001180a000980a001180900098090011bae3010001300c37540022c4a666010600a60146ea80044c8c94ccc038c04400852616375a601e00260166ea8004588c94ccc020c0140044c8c94ccc038c04400852616375c601e00260166ea800854ccc020c00c00454ccc030c02cdd50010a4c2c2c60126ea8004dc3a40044a66600a6004600e6ea80044c8c8c8c94ccc034c04000852616375c601c002601c0046eb8c030004c020dd50008b1b87480015cd2b9c5573aaae7955cfaba05742ae89"
418
463
  };
419
464
 
465
+ // src/types/indigo/interest-oracle.ts
466
+ import { Data as Data7 } from "@lucid-evolution/lucid";
467
+ var InterestOracleDatumSchema = Data7.Object({
468
+ unitaryInterest: Data7.Integer(),
469
+ interestRate: OnChainDecimalSchema,
470
+ lastUpdated: Data7.Integer()
471
+ });
472
+ var InterestOracleDatum = InterestOracleDatumSchema;
473
+ function parseInterestOracleDatum(datum) {
474
+ return Data7.from(datum, InterestOracleDatum);
475
+ }
476
+ function serialiseInterestOracleDatum(datum) {
477
+ return Data7.to(datum, InterestOracleDatum);
478
+ }
479
+ var FeedInterestOracleRedeemerSchema = Data7.Object({
480
+ newInterestRate: OnChainDecimalSchema,
481
+ currentTime: Data7.Integer()
482
+ });
483
+ var FeedInterestOracleRedeemer = FeedInterestOracleRedeemerSchema;
484
+ function serialiseFeedInterestOracleRedeemer(redeemer) {
485
+ return Data7.to(
486
+ redeemer,
487
+ FeedInterestOracleRedeemer
488
+ );
489
+ }
490
+ var InterestOracleParamsSchema = Data7.Object({
491
+ /** Milliseconds */
492
+ biasTime: Data7.Integer(),
493
+ owner: Data7.Bytes()
494
+ });
495
+ var InterestOracleParams = InterestOracleParamsSchema;
496
+ function castInterestOracleParams(params) {
497
+ return Data7.castTo(params, InterestOracleParams);
498
+ }
499
+
500
+ // src/types/indigo/cdp-creator.ts
501
+ import { Data as Data8 } from "@lucid-evolution/lucid";
502
+ var CDPCreatorParamsSchema = Data8.Object({
503
+ cdpCreatorNft: AssetClassSchema,
504
+ cdpAssetCs: Data8.Bytes(),
505
+ cdpAuthTk: AssetClassSchema,
506
+ iAssetAuthTk: AssetClassSchema,
507
+ versionRecordToken: AssetClassSchema,
508
+ cdpScriptHash: Data8.Bytes(),
509
+ collectorValHash: Data8.Bytes(),
510
+ minCollateralInLovelace: Data8.Integer(),
511
+ biasTime: Data8.Integer()
512
+ });
513
+ var CDPCreatorParams = CDPCreatorParamsSchema;
514
+ function castCDPCreatorParams(params) {
515
+ return Data8.castTo(params, CDPCreatorParams);
516
+ }
517
+ var CDPCreatorRedeemerSchema = Data8.Enum([
518
+ Data8.Object({
519
+ CreateCDP: Data8.Object({
520
+ cdpOwner: Data8.Bytes(),
521
+ minted: Data8.Integer(),
522
+ collateral: Data8.Integer(),
523
+ currentTime: Data8.Integer()
524
+ })
525
+ }),
526
+ Data8.Object({ UpgradeCreatorVersion: Data8.Object({}) })
527
+ ]);
528
+ var CDPCreatorRedeemer = CDPCreatorRedeemerSchema;
529
+ function castCDPCreatorRedeemer(params) {
530
+ return Data8.castTo(params, CDPCreatorRedeemer);
531
+ }
532
+
533
+ // src/types/indigo/gov.ts
534
+ import { Data as Data9 } from "@lucid-evolution/lucid";
535
+ var GovDatumSchema = Data9.Object({
536
+ currentProposal: Data9.Integer(),
537
+ protocolParams: Data9.Object({
538
+ proposalDeposit: Data9.Integer(),
539
+ votingPeriod: Data9.Integer(),
540
+ effectiveDelay: Data9.Integer(),
541
+ expirationPeriod: Data9.Integer(),
542
+ collateralFeePercentage: OnChainDecimalSchema,
543
+ proposingPeriod: Data9.Integer(),
544
+ totalShards: Data9.Integer(),
545
+ minimumQuorum: Data9.Integer(),
546
+ maxTreasuryLovelaceSpend: Data9.Integer(),
547
+ maxTreasuryIndySpend: Data9.Integer()
548
+ }),
549
+ currentVersion: Data9.Integer(),
550
+ iassetsCount: Data9.Integer(),
551
+ activeProposals: Data9.Integer(),
552
+ treasuryIndyWithdrawnAmt: Data9.Integer()
553
+ });
554
+ var GovDatum = GovDatumSchema;
555
+ function parseGovDatum(datum) {
556
+ return Data9.from(datum, GovDatum);
557
+ }
558
+ function serialiseGovDatum(d) {
559
+ return Data9.to(d, GovDatum);
560
+ }
561
+ var GovParamsSchema = Data9.Object({
562
+ govNFT: AssetClassSchema,
563
+ pollToken: AssetClassSchema,
564
+ upgradeToken: AssetClassSchema,
565
+ indyAsset: AssetClassSchema,
566
+ versionRecordToken: AssetClassSchema,
567
+ pollManagerValHash: Data9.Bytes(),
568
+ gBiasTime: Data9.Integer(),
569
+ daoIdentityToken: AssetClassSchema,
570
+ iAssetAuthToken: AssetClassSchema
571
+ });
572
+ var GovParams = GovParamsSchema;
573
+ function castGovParams(params) {
574
+ return Data9.castTo(params, GovParams);
575
+ }
576
+
577
+ // src/helpers/time-helpers.ts
578
+ var ONE_SECOND = 1e3;
579
+ var oneHour = 3600000n;
580
+ var oneDay = 86400000n;
581
+ var oneYear = 31536000000n;
582
+
583
+ // src/helpers/interest-oracle.ts
584
+ var unitaryInterestPrecision = 1000000000000000000n;
585
+ var decimalUnit = 1000000n;
586
+ function calculateUnitaryInterest(timePeriod, interestRate) {
587
+ return timePeriod * interestRate * unitaryInterestPrecision / oneYear / decimalUnit;
588
+ }
589
+ function calculateUnitaryInterestSinceOracleLastUpdated(now, oracleDatum) {
590
+ return calculateUnitaryInterest(
591
+ now - oracleDatum.lastUpdated,
592
+ oracleDatum.interestRate.getOnChainInt
593
+ );
594
+ }
595
+ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, interestLastSettled, interestOracleDatum) {
596
+ if (interestOracleDatum.unitaryInterest >= unitaryInterestSnapshot) {
597
+ const interestFromPreviousRates = (interestOracleDatum.unitaryInterest - unitaryInterestSnapshot) * mintedAmount / unitaryInterestPrecision;
598
+ const lastRateInterest = (now - interestOracleDatum.lastUpdated) * interestOracleDatum.interestRate.getOnChainInt * mintedAmount / oneYear / decimalUnit;
599
+ return interestFromPreviousRates + lastRateInterest;
600
+ } else {
601
+ return (now - interestLastSettled) * interestOracleDatum.interestRate.getOnChainInt * mintedAmount / oneYear / decimalUnit;
602
+ }
603
+ }
604
+
420
605
  // src/contracts/cdp.ts
421
606
  var CDPContract = class _CDPContract {
422
- static async openPosition(asset, collateralAmount, mintedAmount, params, lucid, assetRef, priceOracleRef, interestOracleRef, cdpCreatorRef, collectorRef) {
607
+ static async openPosition(asset, collateralAmount, mintedAmount, params, lucid, assetRef, priceOracleRef, interestOracleRef, cdpCreatorRef, collectorRef, now = Date.now()) {
423
608
  const [pkh, skh] = await addrDetails(lucid);
424
- const now = Date.now();
425
- const assetOut = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, params, lucid) : IAssetHelpers.findIAssetByName(asset, params, lucid));
426
- if ("getOnChainPrice" in assetOut.datum.price)
427
- return Promise.reject("Trying to open CDP against delisted asset");
428
- const oracleAsset = assetOut.datum.price;
609
+ const assetOut = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(asset, params, lucid));
610
+ if (!assetOut || !assetOut.datum) throw new Error("Unable to find IAsset");
611
+ if ("Delisted" in assetOut.datum.price)
612
+ return Promise.reject(
613
+ new Error("Trying to open CDP against delisted asset")
614
+ );
615
+ const oracleAsset = assetOut.datum.price.Oracle.oracleNft.asset;
429
616
  const oracleOut = priceOracleRef ? (await lucid.utxosByOutRef([priceOracleRef]))[0] : await lucid.utxoByUnit(
430
- oracleAsset[0].unCurrencySymbol + fromText5(oracleAsset[1].unTokenName)
431
- );
432
- if (!oracleOut.datum) return Promise.reject("Price Oracle datum not found");
433
- const oracleDatum = PriceOracleContract.decodePriceOracleDatum(
434
- oracleOut.datum
617
+ oracleAsset.currencySymbol + oracleAsset.tokenName
435
618
  );
436
- const interestOracleAsset = assetOut.datum.interestOracle;
619
+ if (!oracleOut.datum)
620
+ return Promise.reject(new Error("Price Oracle datum not found"));
621
+ const oracleDatum = parsePriceOracleDatum(oracleOut.datum);
622
+ const interestOracleAsset = assetOut.datum.interestOracleNft;
437
623
  const interestOracleOut = interestOracleRef ? (await lucid.utxosByOutRef([interestOracleRef]))[0] : await lucid.utxoByUnit(
438
- interestOracleAsset[0].unCurrencySymbol + fromText5(interestOracleAsset[1].unTokenName)
624
+ interestOracleAsset.currencySymbol + interestOracleAsset.tokenName
439
625
  );
440
626
  if (!interestOracleOut.datum)
441
- return Promise.reject("Interest Oracle datum not found");
442
- const interestOracleDatum = InterestOracleContract.decodeInterestOracleDatum(interestOracleOut.datum);
627
+ return Promise.reject(new Error("Interest Oracle datum not found"));
628
+ const interestOracleDatum = parseInterestOracleDatum(
629
+ interestOracleOut.datum
630
+ );
443
631
  const cdpCreatorOut = getRandomElement(
444
632
  cdpCreatorRef ? await lucid.utxosByOutRef([cdpCreatorRef]) : await lucid.utxosAtWithUnit(
445
- CDPCreatorContract.address(params.cdpCreatorParams, lucid),
446
- params.cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + fromText5(params.cdpCreatorParams.cdpCreatorNft[1].unTokenName)
633
+ credentialToAddress3(lucid.config().network, {
634
+ type: "Script",
635
+ hash: params.validatorHashes.cdpCreatorHash
636
+ }),
637
+ params.cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + fromText4(params.cdpCreatorParams.cdpCreatorNft[1].unTokenName)
447
638
  )
448
639
  );
449
- const cdpCreatorRedeemer = CDPCreatorContract.redeemer(
450
- pkh,
451
- mintedAmount,
452
- collateralAmount,
453
- BigInt(now)
454
- );
455
- const cdpCreatorScriptRefUtxo = await CDPCreatorContract.scriptRef(
456
- params.scriptReferences,
640
+ const cdpCreatorRedeemer = castCDPCreatorRedeemer({
641
+ CreateCDP: {
642
+ cdpOwner: pkh.hash,
643
+ minted: mintedAmount,
644
+ collateral: collateralAmount,
645
+ currentTime: BigInt(now)
646
+ }
647
+ });
648
+ const cdpCreatorScriptRefUtxo = await scriptRef(
649
+ params.scriptReferences.cdpCreatorValidatorRef,
457
650
  lucid
458
651
  );
459
652
  const cdpAddress = _CDPContract.address(params.cdpParams, lucid, skh);
460
- const cdpToken = params.cdpParams.cdpAuthToken[0].unCurrencySymbol + fromText5(params.cdpParams.cdpAuthToken[1].unTokenName);
653
+ const cdpToken = params.cdpParams.cdpAuthToken[0].unCurrencySymbol + fromText4(params.cdpParams.cdpAuthToken[1].unTokenName);
461
654
  const cdpValue = {
462
655
  lovelace: collateralAmount
463
656
  };
464
657
  cdpValue[cdpToken] = 1n;
465
- const newSnapshot = InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
658
+ const newSnapshot = calculateUnitaryInterestSinceOracleLastUpdated(
466
659
  BigInt(now),
467
660
  interestOracleDatum
468
661
  ) + interestOracleDatum.unitaryInterest;
469
- const cdpDatum = _CDPContract.datum(pkh, asset, mintedAmount, {
470
- type: "ActiveCDPInterestTracking",
471
- last_settled: BigInt(now),
472
- unitary_interest_snapshot: newSnapshot
473
- });
474
- const assetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + fromText5(asset);
662
+ const cdpDatum = {
663
+ cdpOwner: pkh.hash,
664
+ iasset: fromText4(asset),
665
+ mintedAmt: mintedAmount,
666
+ cdpFees: {
667
+ ActiveCDPInterestTracking: {
668
+ lastSettled: BigInt(now),
669
+ unitaryInterestSnapshot: newSnapshot
670
+ }
671
+ }
672
+ };
673
+ const assetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + fromText4(asset);
475
674
  const cdpTokenMintValue = {};
476
675
  cdpTokenMintValue[cdpToken] = 1n;
477
676
  const iassetTokenMintValue = {};
@@ -486,21 +685,21 @@ var CDPContract = class _CDPContract {
486
685
  );
487
686
  const debtMintingFee = calculateFeeFromPercentage(
488
687
  BigInt(assetOut.datum.debtMintingFeePercentage.getOnChainInt),
489
- mintedAmount * oracleDatum.price / 1000000n
688
+ mintedAmount * oracleDatum.price.getOnChainInt / 1000000n
490
689
  );
491
690
  const cappedValidateTo = oracleDatum.expiration - 20001n;
492
691
  const timeValidFrom = now - 1e3;
493
- const timeValidTo_ = now + params.cdpCreatorParams.biasTime - 1e3;
692
+ const timeValidTo_ = now + Number(params.cdpCreatorParams.biasTime) - 1e3;
494
693
  const timeValidTo = cappedValidateTo <= timeValidFrom ? timeValidTo_ : Math.min(timeValidTo_, Number(cappedValidateTo));
495
- const tx = lucid.newTx().collectFrom([cdpCreatorOut], Data7.to(cdpCreatorRedeemer)).readFrom([cdpCreatorScriptRefUtxo]).pay.ToContract(
694
+ const tx = lucid.newTx().collectFrom([cdpCreatorOut], Data10.to(cdpCreatorRedeemer)).readFrom([cdpCreatorScriptRefUtxo]).pay.ToContract(
496
695
  cdpAddress,
497
- { kind: "inline", value: Data7.to(cdpDatum) },
696
+ { kind: "inline", value: serialiseCDPDatum(cdpDatum) },
498
697
  cdpValue
499
698
  ).pay.ToContract(
500
699
  cdpCreatorOut.address,
501
700
  { kind: "inline", value: cdpCreatorOut.datum },
502
701
  cdpCreatorOut.assets
503
- ).readFrom([oracleOut, interestOracleOut, assetOut.utxo]).mintAssets(cdpTokenMintValue, Data7.to(new Constr7(0, []))).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(iassetTokenMintValue, Data7.to(new Constr7(0, []))).readFrom([iAssetTokenScriptRefUtxo]).addSignerKey(pkh.hash).validFrom(Number(now - 6e4)).validTo(Number(timeValidTo));
702
+ ).readFrom([oracleOut, interestOracleOut, assetOut.utxo]).mintAssets(cdpTokenMintValue, Data10.to(new Constr3(0, []))).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(iassetTokenMintValue, Data10.to(new Constr3(0, []))).readFrom([iAssetTokenScriptRefUtxo]).addSignerKey(pkh.hash).validFrom(Number(now - 100)).validTo(Number(timeValidTo));
504
703
  if (debtMintingFee > 0) {
505
704
  await CollectorContract.feeTx(
506
705
  debtMintingFee,
@@ -573,104 +772,110 @@ var CDPContract = class _CDPContract {
573
772
  );
574
773
  }
575
774
  static async adjust(cdpRef, collateralAmount, mintAmount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
576
- const [pkh, skh] = await addrDetails(lucid);
775
+ const [pkh, _] = await addrDetails(lucid);
577
776
  const now = Date.now();
578
- if (!pkh)
579
- return Promise.reject(
580
- "Unable to determine the pub key hash of the wallet"
581
- );
582
777
  const cdp = (await lucid.utxosByOutRef([cdpRef]))[0];
583
- if (!cdp.datum) throw "Unable to find CDP Datum";
584
- const cdpDatum = _CDPContract.decodeCdpDatum(cdp.datum);
585
- if (cdpDatum.type !== "CDP") throw "Invalid CDP Datum";
586
- const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, params, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.asset, params, lucid));
778
+ if (!cdp.datum) throw new Error("Unable to find CDP Datum");
779
+ const cdpDatum = parseCDPDatum(cdp.datum);
780
+ const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.iasset, params, lucid));
587
781
  const gov = govRef ? (await lucid.utxosByOutRef([govRef]))[0] : await lucid.utxoByUnit(
588
- params.govParams.govNFT[0].unCurrencySymbol + fromText5(params.govParams.govNFT[1].unTokenName)
782
+ params.govParams.govNFT[0].unCurrencySymbol + fromText4(params.govParams.govNFT[1].unTokenName)
589
783
  );
590
- if (!gov.datum) throw "Unable to find Gov Datum";
591
- const govData = GovContract.decodeGovDatum(gov.datum);
592
- if (!govData) throw "No Governance datum found";
784
+ if (!gov.datum) throw new Error("Unable to find Gov Datum");
785
+ const govData = parseGovDatum(gov.datum);
593
786
  const cdpScriptRefUtxo = await _CDPContract.scriptRef(
594
787
  params.scriptReferences,
595
788
  lucid
596
789
  );
597
790
  const cdpAssets = Object.assign({}, cdp.assets);
598
791
  cdpAssets["lovelace"] = cdp.assets["lovelace"] + collateralAmount;
599
- const interestOracleAsset = iAsset.datum.interestOracle;
792
+ const interestOracleAsset = iAsset.datum.interestOracleNft;
600
793
  const interestOracleOut = interestOracleRef ? (await lucid.utxosByOutRef([interestOracleRef]))[0] : await lucid.utxoByUnit(
601
- interestOracleAsset[0].unCurrencySymbol + fromText5(interestOracleAsset[1].unTokenName)
794
+ interestOracleAsset.currencySymbol + fromText4(interestOracleAsset.tokenName)
602
795
  );
603
796
  if (!interestOracleOut.datum)
604
- return Promise.reject("Interest Oracle datum not found");
605
- const interestOracleDatum = InterestOracleContract.decodeInterestOracleDatum(interestOracleOut.datum);
606
- let tx = lucid.newTx().collectFrom([cdp], Data7.to(new Constr7(0, [BigInt(now), mintAmount, collateralAmount]))).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
607
- if (!cdp.datum) throw "Unable to find CDP Datum";
608
- let cdpD = _CDPContract.decodeCdpDatum(cdp.datum);
609
- if (!cdpD || cdpD.type !== "CDP") throw "Invalid CDP Datum";
610
- if (cdpD.fees.type !== "ActiveCDPInterestTracking")
611
- throw "Invalid CDP Fees";
612
- const newSnapshot = InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
797
+ return Promise.reject(new Error("Interest Oracle datum not found"));
798
+ const interestOracleDatum = parseInterestOracleDatum(
799
+ interestOracleOut.datum
800
+ );
801
+ const tx = lucid.newTx().collectFrom(
802
+ [cdp],
803
+ Data10.to(new Constr3(0, [BigInt(now), mintAmount, collateralAmount]))
804
+ ).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
805
+ if (!cdp.datum) throw new Error("Unable to find CDP Datum");
806
+ const cdpD = parseCDPDatum(cdp.datum);
807
+ if (!("ActiveCDPInterestTracking" in cdpD.cdpFees))
808
+ throw new Error("Invalid CDP Fees");
809
+ const newSnapshot = calculateUnitaryInterestSinceOracleLastUpdated(
613
810
  BigInt(now),
614
811
  interestOracleDatum
615
812
  ) + interestOracleDatum.unitaryInterest;
616
813
  const cdpD_ = {
617
814
  ...cdpD,
618
- mintedAmount: cdpD.mintedAmount + mintAmount,
619
- fees: {
620
- type: "ActiveCDPInterestTracking",
621
- last_settled: BigInt(now),
622
- unitary_interest_snapshot: newSnapshot
815
+ mintedAmt: cdpD.mintedAmt + mintAmount,
816
+ cdpFees: {
817
+ ActiveCDPInterestTracking: {
818
+ lastSettled: BigInt(now),
819
+ unitaryInterestSnapshot: newSnapshot
820
+ }
623
821
  }
624
822
  };
625
823
  tx.pay.ToContract(
626
824
  cdp.address,
627
825
  {
628
826
  kind: "inline",
629
- value: _CDPContract.encodeCdpDatum(cdpD_)
827
+ value: serialiseCDPDatum(cdpD_)
630
828
  },
631
829
  cdpAssets
632
830
  );
633
831
  const oracleAsset = iAsset.datum.price;
832
+ if (!("Oracle" in oracleAsset)) throw new Error("Invalid oracle asset");
634
833
  const oracleRefInput = priceOracleRef ? (await lucid.utxosByOutRef([priceOracleRef]))[0] : await lucid.utxoByUnit(
635
- oracleAsset[0].unCurrencySymbol + fromText5(oracleAsset[1].unTokenName)
834
+ oracleAsset.Oracle.oracleNft.asset.currencySymbol + fromText4(oracleAsset.Oracle.oracleNft.asset.tokenName)
636
835
  );
637
- if (!oracleRefInput.datum) return Promise.reject("Invalid oracle input");
638
- const od = PriceOracleContract.decodePriceOracleDatum(oracleRefInput.datum);
639
- if (!od) return Promise.reject("Invalid oracle input");
836
+ if (!oracleRefInput.datum)
837
+ return Promise.reject(new Error("Invalid oracle input"));
838
+ const od = parsePriceOracleDatum(oracleRefInput.datum);
839
+ if (!od) return Promise.reject(new Error("Invalid oracle input"));
640
840
  const cappedValidateTo = od.expiration - 20001n;
641
841
  const timeValidFrom = now - 1e3;
642
- const timeValidTo_ = now + params.cdpCreatorParams.biasTime - 1e3;
842
+ const timeValidTo_ = now + Number(params.cdpCreatorParams.biasTime) - 1e3;
643
843
  const timeValidTo = cappedValidateTo <= timeValidFrom ? timeValidTo_ : Math.min(timeValidTo_, Number(cappedValidateTo));
644
844
  tx.readFrom([oracleRefInput]).validFrom(Number(timeValidFrom)).validTo(Number(timeValidTo));
645
845
  let fee = 0n;
646
846
  if (collateralAmount < 0) {
647
847
  fee += calculateFeeFromPercentage(
648
- govData.protocolParams.collateralFeePercentage,
848
+ govData.protocolParams.collateralFeePercentage.getOnChainInt,
649
849
  collateralAmount
650
850
  );
651
851
  }
652
852
  if (mintAmount > 0) {
653
853
  fee += calculateFeeFromPercentage(
654
854
  iAsset.datum.debtMintingFeePercentage.getOnChainInt,
655
- mintAmount * od.price / 1000000n
855
+ mintAmount * od.price.getOnChainInt / 1000000n
656
856
  );
657
857
  }
658
- const interestPaymentAsset = InterestOracleContract.calculateAccruedInterest(
858
+ const interestPaymentAsset = calculateAccruedInterest(
659
859
  BigInt(now),
660
- cdpD.fees.unitary_interest_snapshot,
661
- cdpD.mintedAmount,
662
- cdpD.fees.last_settled,
860
+ cdpD.cdpFees.ActiveCDPInterestTracking.unitaryInterestSnapshot,
861
+ cdpD.mintedAmt,
862
+ cdpD.cdpFees.ActiveCDPInterestTracking.lastSettled,
663
863
  interestOracleDatum
664
864
  );
665
- const interestPayment = interestPaymentAsset * od.price / 1000000n;
865
+ const interestPayment = interestPaymentAsset * od.price.getOnChainInt / 1000000n;
666
866
  const interestCollectorPayment = calculateFeeFromPercentage(
667
867
  iAsset.datum.interestCollectorPortionPercentage.getOnChainInt,
668
868
  interestPayment
669
869
  );
670
870
  const interestTreasuryPayment = interestPayment - interestCollectorPayment;
671
- console.log(interestPayment, interestCollectorPayment, interestTreasuryPayment);
672
871
  if (interestTreasuryPayment > 0) {
673
- await TreasuryContract.feeTx(interestTreasuryPayment, lucid, params, tx, treasuryRef);
872
+ await TreasuryContract.feeTx(
873
+ interestTreasuryPayment,
874
+ lucid,
875
+ params,
876
+ tx,
877
+ treasuryRef
878
+ );
674
879
  }
675
880
  fee += interestCollectorPayment;
676
881
  tx.readFrom([interestOracleOut]);
@@ -679,12 +884,12 @@ var CDPContract = class _CDPContract {
679
884
  params.scriptReferences,
680
885
  lucid
681
886
  );
682
- const iassetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + fromText5(cdpD.asset);
887
+ const iassetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + cdpD.iasset;
683
888
  const mintValue = {};
684
889
  mintValue[iassetToken] = mintAmount;
685
890
  tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(
686
891
  mintValue,
687
- Data7.to(new Constr7(0, []))
892
+ Data10.to(new Constr3(0, []))
688
893
  );
689
894
  }
690
895
  if (fee > 0n) {
@@ -693,275 +898,123 @@ var CDPContract = class _CDPContract {
693
898
  return tx;
694
899
  }
695
900
  static async close(cdpRef, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
696
- const [pkh, skh] = await addrDetails(lucid);
901
+ const [pkh, _] = await addrDetails(lucid);
697
902
  const now = Date.now();
698
- if (!pkh)
699
- return Promise.reject(
700
- "Unable to determine the pub key hash of the wallet"
701
- );
702
903
  const cdp = (await lucid.utxosByOutRef([cdpRef]))[0];
703
- if (!cdp.datum) throw "Unable to find CDP Datum";
704
- const cdpDatum = _CDPContract.decodeCdpDatum(cdp.datum);
705
- if (cdpDatum.type !== "CDP") throw "Invalid CDP Datum";
706
- const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, params, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.asset, params, lucid));
904
+ if (!cdp.datum) throw new Error("Unable to find CDP Datum");
905
+ const cdpDatum = parseCDPDatum(cdp.datum);
906
+ const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.iasset, params, lucid));
707
907
  const gov = govRef ? (await lucid.utxosByOutRef([govRef]))[0] : await lucid.utxoByUnit(
708
- params.govParams.govNFT[0].unCurrencySymbol + fromText5(params.govParams.govNFT[1].unTokenName)
908
+ params.govParams.govNFT[0].unCurrencySymbol + fromText4(params.govParams.govNFT[1].unTokenName)
709
909
  );
710
- if (!gov.datum) throw "Unable to find Gov Datum";
711
- const govData = GovContract.decodeGovDatum(gov.datum);
712
- if (!govData) throw "No Governance datum found";
910
+ if (!gov.datum) throw new Error("Unable to find Gov Datum");
713
911
  const cdpScriptRefUtxo = await _CDPContract.scriptRef(
714
912
  params.scriptReferences,
715
913
  lucid
716
914
  );
717
- const interestOracleAsset = iAsset.datum.interestOracle;
915
+ const interestOracleAsset = iAsset.datum.interestOracleNft;
718
916
  const interestOracleOut = interestOracleRef ? (await lucid.utxosByOutRef([interestOracleRef]))[0] : await lucid.utxoByUnit(
719
- interestOracleAsset[0].unCurrencySymbol + fromText5(interestOracleAsset[1].unTokenName)
917
+ interestOracleAsset.currencySymbol + fromText4(interestOracleAsset.tokenName)
720
918
  );
721
919
  if (!interestOracleOut.datum)
722
- return Promise.reject("Interest Oracle datum not found");
723
- const interestOracleDatum = InterestOracleContract.decodeInterestOracleDatum(interestOracleOut.datum);
724
- let tx = lucid.newTx().collectFrom([cdp], Data7.to(new Constr7(1, [BigInt(now)]))).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
725
- if (!cdp.datum) throw "Unable to find CDP Datum";
726
- let cdpD = _CDPContract.decodeCdpDatum(cdp.datum);
727
- if (!cdpD || cdpD.type !== "CDP") throw "Invalid CDP Datum";
728
- if (cdpD.fees.type !== "ActiveCDPInterestTracking")
729
- throw "Invalid CDP Fees";
730
- const oracleAsset = iAsset.datum.price;
920
+ return Promise.reject(new Error("Interest Oracle datum not found"));
921
+ const interestOracleDatum = parseInterestOracleDatum(
922
+ interestOracleOut.datum
923
+ );
924
+ const tx = lucid.newTx().collectFrom([cdp], Data10.to(new Constr3(1, [BigInt(now)]))).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
925
+ if (!cdp.datum) throw new Error("Unable to find CDP Datum");
926
+ const cdpD = parseCDPDatum(cdp.datum);
927
+ if (!("ActiveCDPInterestTracking" in cdpD.cdpFees))
928
+ throw new Error("Invalid CDP Fees");
929
+ if (!("Oracle" in iAsset.datum.price))
930
+ throw new Error("iAsset is delisted");
931
+ const oracleAsset = iAsset.datum.price.Oracle.oracleNft.asset;
731
932
  const oracleRefInput = priceOracleRef ? (await lucid.utxosByOutRef([priceOracleRef]))[0] : await lucid.utxoByUnit(
732
- oracleAsset[0].unCurrencySymbol + fromText5(oracleAsset[1].unTokenName)
933
+ oracleAsset.currencySymbol + fromText4(oracleAsset.tokenName)
733
934
  );
734
- if (!oracleRefInput.datum) return Promise.reject("Invalid oracle input");
735
- const od = PriceOracleContract.decodePriceOracleDatum(oracleRefInput.datum);
736
- if (!od) return Promise.reject("Invalid oracle input");
935
+ if (!oracleRefInput.datum)
936
+ return Promise.reject(new Error("Invalid oracle input"));
937
+ const od = parsePriceOracleDatum(oracleRefInput.datum);
737
938
  const cappedValidateTo = od.expiration - 20001n;
738
939
  const timeValidFrom = now - 1e3;
739
- const timeValidTo_ = now + params.cdpCreatorParams.biasTime - 1e3;
940
+ const timeValidTo_ = now + Number(params.cdpCreatorParams.biasTime) - 1e3;
740
941
  const timeValidTo = cappedValidateTo <= timeValidFrom ? timeValidTo_ : Math.min(timeValidTo_, Number(cappedValidateTo));
741
942
  tx.readFrom([oracleRefInput]).validFrom(Number(timeValidFrom)).validTo(Number(timeValidTo));
742
943
  let fee = 0n;
743
- const interestPaymentAsset = InterestOracleContract.calculateAccruedInterest(
944
+ const interestPaymentAsset = calculateAccruedInterest(
744
945
  BigInt(now),
745
- cdpD.fees.unitary_interest_snapshot,
746
- cdpD.mintedAmount,
747
- cdpD.fees.last_settled,
946
+ cdpD.cdpFees.ActiveCDPInterestTracking.unitaryInterestSnapshot,
947
+ cdpD.mintedAmt,
948
+ cdpD.cdpFees.ActiveCDPInterestTracking.lastSettled,
748
949
  interestOracleDatum
749
950
  );
750
- const interestPayment = interestPaymentAsset * od.price / 1000000n;
951
+ const interestPayment = interestPaymentAsset * od.price.getOnChainInt / 1000000n;
751
952
  const interestCollectorPayment = calculateFeeFromPercentage(
752
953
  iAsset.datum.interestCollectorPortionPercentage.getOnChainInt,
753
954
  interestPayment
754
955
  );
755
956
  const interestTreasuryPayment = interestPayment - interestCollectorPayment;
756
- console.log(interestPayment, interestCollectorPayment, interestTreasuryPayment);
757
957
  if (interestTreasuryPayment > 0) {
758
- await TreasuryContract.feeTx(interestTreasuryPayment, lucid, params, tx, treasuryRef);
759
- }
760
- fee += interestCollectorPayment;
761
- tx.readFrom([interestOracleOut]);
958
+ await TreasuryContract.feeTx(
959
+ interestTreasuryPayment,
960
+ lucid,
961
+ params,
962
+ tx,
963
+ treasuryRef
964
+ );
965
+ }
966
+ fee += interestCollectorPayment;
967
+ tx.readFrom([interestOracleOut]);
762
968
  const iAssetTokenScriptRefUtxo = await _CDPContract.assetTokenRef(
763
969
  params.scriptReferences,
764
970
  lucid
765
971
  );
766
- const iassetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + fromText5(cdpD.asset);
972
+ const iassetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + cdpD.iasset;
767
973
  const assetBurnValue = {};
768
- assetBurnValue[iassetToken] = -BigInt(cdpD.mintedAmount);
974
+ assetBurnValue[iassetToken] = -BigInt(cdpD.mintedAmt);
769
975
  const cdpTokenBurnValue = {};
770
- cdpTokenBurnValue[params.cdpParams.cdpAuthToken[0].unCurrencySymbol + fromText5(params.cdpParams.cdpAuthToken[1].unTokenName)] = -1n;
976
+ cdpTokenBurnValue[params.cdpParams.cdpAuthToken[0].unCurrencySymbol + fromText4(params.cdpParams.cdpAuthToken[1].unTokenName)] = -1n;
771
977
  const cdpAuthTokenScriptRefUtxo = await _CDPContract.cdpAuthTokenRef(
772
978
  params.scriptReferences,
773
979
  lucid
774
980
  );
775
- tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(
776
- assetBurnValue,
777
- Data7.to(new Constr7(0, []))
778
- ).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(
779
- cdpTokenBurnValue,
780
- Data7.to(new Constr7(0, []))
781
- );
981
+ tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(assetBurnValue, Data10.to(new Constr3(0, []))).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(cdpTokenBurnValue, Data10.to(new Constr3(0, [])));
782
982
  if (fee > 0n) {
783
983
  await CollectorContract.feeTx(fee, lucid, params, tx, collectorRef);
784
984
  }
785
985
  return tx;
786
986
  }
787
- static decodeCdpDatum(datum) {
788
- const cdpDatum = Data7.from(datum);
789
- if (cdpDatum.index == 1 && cdpDatum.fields[0].index == 0) {
790
- const iasset = cdpDatum.fields[0].fields;
791
- return {
792
- type: "IAsset",
793
- name: toText(iasset[0]),
794
- price: iasset[1].index === 0 ? { getOnChainInt: iasset[1].fields[0] } : [
795
- { unCurrencySymbol: iasset[1].fields[0].fields[0].fields[0] },
796
- {
797
- unTokenName: toText(iasset[1].fields[0].fields[0].fields[1])
798
- }
799
- ],
800
- interestOracle: [
801
- { unCurrencySymbol: iasset[2].fields[0] },
802
- { unTokenName: toText(iasset[2].fields[1]) }
803
- ],
804
- redemptionRatioPercentage: { getOnChainInt: iasset[3].fields[0] },
805
- maintenanceRatioPercentage: { getOnChainInt: iasset[4].fields[0] },
806
- liquidationRatioPercentage: { getOnChainInt: iasset[5].fields[0] },
807
- debtMintingFeePercentage: { getOnChainInt: iasset[6].fields[0] },
808
- liquidationProcessingFeePercentage: {
809
- getOnChainInt: iasset[7].fields[0]
810
- },
811
- stabilityPoolWithdrawalFeePercentage: {
812
- getOnChainInt: iasset[8].fields[0]
813
- },
814
- redemptionReimbursementPercentage: {
815
- getOnChainInt: iasset[9].fields[0]
816
- },
817
- redemptionProcessingFeePercentage: {
818
- getOnChainInt: iasset[10].fields[0]
819
- },
820
- interestCollectorPortionPercentage: {
821
- getOnChainInt: iasset[11].fields[0]
822
- },
823
- firstAsset: iasset[12].index === 1,
824
- nextAsset: iasset[13].index === 0 ? toText(iasset[13].fields[0]) : void 0
825
- };
826
- } else if (cdpDatum.index == 0 && cdpDatum.fields[0].index == 0) {
827
- const cdp = cdpDatum.fields[0].fields;
828
- return {
829
- type: "CDP",
830
- owner: cdp[0].fields[0],
831
- asset: toText(cdp[1]),
832
- mintedAmount: cdp[2],
833
- fees: cdp[3].index === 0 ? {
834
- type: "ActiveCDPInterestTracking",
835
- last_settled: cdp[3].fields[0],
836
- unitary_interest_snapshot: cdp[3].fields[1]
837
- } : {
838
- type: "FrozenCDPAccumulatedFees",
839
- lovelaces_treasury: cdp[3].fields[0],
840
- lovelaces_indy_stakers: cdp[3].fields[1]
841
- }
842
- };
843
- }
844
- throw "Invalid CDP Datum provided";
845
- }
846
- static encodeCdpDatum(datum) {
847
- if (datum.type === "CDP") {
848
- return Data7.to(
849
- new Constr7(0, [
850
- new Constr7(0, [
851
- datum.owner ? new Constr7(0, [datum.owner]) : new Constr7(1, []),
852
- fromText5(datum.asset),
853
- BigInt(datum.mintedAmount),
854
- datum.fees.type === "ActiveCDPInterestTracking" ? new Constr7(0, [
855
- datum.fees.last_settled,
856
- datum.fees.unitary_interest_snapshot
857
- ]) : new Constr7(1, [
858
- datum.fees.lovelaces_treasury,
859
- datum.fees.lovelaces_indy_stakers
860
- ])
861
- ])
862
- ])
863
- );
864
- } else if (datum.type === "IAsset") {
865
- return Data7.to(
866
- new Constr7(1, [
867
- new Constr7(0, [
868
- fromText5(datum.name),
869
- "getOnChainInt" in datum.price ? new Constr7(0, [
870
- new Constr7(0, [BigInt(datum.price.getOnChainInt)])
871
- ]) : new Constr7(1, [
872
- new Constr7(0, [
873
- new Constr7(0, [
874
- datum.price[0].unCurrencySymbol,
875
- fromText5(datum.price[1].unTokenName)
876
- ])
877
- ])
878
- ]),
879
- new Constr7(0, [
880
- datum.interestOracle[0].unCurrencySymbol,
881
- fromText5(datum.interestOracle[1].unTokenName)
882
- ]),
883
- new Constr7(0, [
884
- BigInt(datum.redemptionRatioPercentage.getOnChainInt)
885
- ]),
886
- new Constr7(0, [
887
- BigInt(datum.maintenanceRatioPercentage.getOnChainInt)
888
- ]),
889
- new Constr7(0, [
890
- BigInt(datum.liquidationRatioPercentage.getOnChainInt)
891
- ]),
892
- new Constr7(0, [
893
- BigInt(datum.debtMintingFeePercentage.getOnChainInt)
894
- ]),
895
- new Constr7(0, [
896
- BigInt(datum.liquidationProcessingFeePercentage.getOnChainInt)
897
- ]),
898
- new Constr7(0, [
899
- BigInt(datum.stabilityPoolWithdrawalFeePercentage.getOnChainInt)
900
- ]),
901
- new Constr7(0, [
902
- BigInt(datum.redemptionReimbursementPercentage.getOnChainInt)
903
- ]),
904
- new Constr7(0, [
905
- BigInt(datum.redemptionProcessingFeePercentage.getOnChainInt)
906
- ]),
907
- new Constr7(0, [
908
- BigInt(datum.interestCollectorPortionPercentage.getOnChainInt)
909
- ]),
910
- datum.firstAsset ? new Constr7(1, []) : new Constr7(0, []),
911
- datum.nextAsset ? new Constr7(0, [fromText5(datum.nextAsset)]) : new Constr7(1, [])
912
- ])
913
- ])
914
- );
915
- }
916
- throw "Invalid CDP Datum provided";
917
- }
918
- static datum(hash, asset, mintedAmount, fees) {
919
- return new Constr7(0, [
920
- new Constr7(0, [
921
- new Constr7(0, [hash.hash]),
922
- fromText5(asset),
923
- BigInt(mintedAmount),
924
- fees.type === "ActiveCDPInterestTracking" ? new Constr7(0, [
925
- BigInt(fees.last_settled),
926
- BigInt(fees.unitary_interest_snapshot)
927
- ]) : new Constr7(0, [
928
- BigInt(fees.lovelaces_treasury),
929
- BigInt(fees.lovelaces_indy_stakers)
930
- ])
931
- ])
932
- ]);
933
- }
934
987
  static validator(params) {
935
988
  return {
936
989
  type: _cdpValidator.type,
937
- script: applyParamsToScript4(_cdpValidator.cborHex, [
938
- new Constr7(0, [
939
- new Constr7(0, [
990
+ script: applyParamsToScript3(_cdpValidator.cborHex, [
991
+ new Constr3(0, [
992
+ new Constr3(0, [
940
993
  params.cdpAuthToken[0].unCurrencySymbol,
941
- fromText5(params.cdpAuthToken[1].unTokenName)
994
+ fromText4(params.cdpAuthToken[1].unTokenName)
942
995
  ]),
943
996
  params.cdpAssetSymbol.unCurrencySymbol,
944
- new Constr7(0, [
997
+ new Constr3(0, [
945
998
  params.iAssetAuthToken[0].unCurrencySymbol,
946
- fromText5(params.iAssetAuthToken[1].unTokenName)
999
+ fromText4(params.iAssetAuthToken[1].unTokenName)
947
1000
  ]),
948
- new Constr7(0, [
1001
+ new Constr3(0, [
949
1002
  params.stabilityPoolAuthToken[0].unCurrencySymbol,
950
- fromText5(params.stabilityPoolAuthToken[1].unTokenName)
1003
+ fromText4(params.stabilityPoolAuthToken[1].unTokenName)
951
1004
  ]),
952
- new Constr7(0, [
1005
+ new Constr3(0, [
953
1006
  params.versionRecordToken[0].unCurrencySymbol,
954
- fromText5(params.versionRecordToken[1].unTokenName)
1007
+ fromText4(params.versionRecordToken[1].unTokenName)
955
1008
  ]),
956
- new Constr7(0, [
1009
+ new Constr3(0, [
957
1010
  params.upgradeToken[0].unCurrencySymbol,
958
- fromText5(params.upgradeToken[1].unTokenName)
1011
+ fromText4(params.upgradeToken[1].unTokenName)
959
1012
  ]),
960
1013
  params.collectorValHash,
961
1014
  params.spValHash,
962
- new Constr7(0, [
1015
+ new Constr3(0, [
963
1016
  params.govNFT[0].unCurrencySymbol,
964
- fromText5(params.govNFT[1].unTokenName)
1017
+ fromText4(params.govNFT[1].unTokenName)
965
1018
  ]),
966
1019
  BigInt(params.minCollateralInLovelace),
967
1020
  BigInt(params.partialRedemptionExtraFeeLovelace),
@@ -972,14 +1025,14 @@ var CDPContract = class _CDPContract {
972
1025
  };
973
1026
  }
974
1027
  static validatorHash(params) {
975
- return validatorToScriptHash4(_CDPContract.validator(params));
1028
+ return validatorToScriptHash3(_CDPContract.validator(params));
976
1029
  }
977
1030
  static address(cdpParams, lucid, skh) {
978
1031
  const network = lucid.config().network;
979
1032
  if (!network) {
980
1033
  throw new Error("Network configuration is undefined");
981
1034
  }
982
- return validatorToAddress4(network, _CDPContract.validator(cdpParams), skh);
1035
+ return validatorToAddress3(network, _CDPContract.validator(cdpParams), skh);
983
1036
  }
984
1037
  static scriptRef(params, lucid) {
985
1038
  return scriptRef(params.cdpValidatorRef, lucid);
@@ -995,42 +1048,1942 @@ var CDPContract = class _CDPContract {
995
1048
  }
996
1049
  };
997
1050
 
998
- // src/helpers/cdp-helpers.ts
999
- var CDPHelpers = class {
1000
- static async cdps(params, lucid) {
1001
- throw new Error("Not implemented");
1051
+ // src/contracts/gov.ts
1052
+ var GovContract = class {
1053
+ };
1054
+
1055
+ // src/contracts/stability-pool.ts
1056
+ import {
1057
+ Constr as Constr4,
1058
+ fromText as fromText6,
1059
+ validatorToScriptHash as validatorToScriptHash4,
1060
+ Data as Data12,
1061
+ credentialToAddress as credentialToAddress4
1062
+ } from "@lucid-evolution/lucid";
1063
+
1064
+ // src/types/indigo/stability-pool.ts
1065
+ import { Data as Data11 } from "@lucid-evolution/lucid";
1066
+ import { match as match3, P as P3 } from "ts-pattern";
1067
+ var SPIntegerSchema = Data11.Object({
1068
+ value: Data11.Integer()
1069
+ });
1070
+ var SPInteger = SPIntegerSchema;
1071
+ var StabilityPoolSnapshotSchema = Data11.Object({
1072
+ productVal: SPIntegerSchema,
1073
+ depositVal: SPIntegerSchema,
1074
+ sumVal: SPIntegerSchema,
1075
+ epoch: Data11.Integer(),
1076
+ scale: Data11.Integer()
1077
+ });
1078
+ var StabilityPoolSnapshot = StabilityPoolSnapshotSchema;
1079
+ var EpochToScaleToSumSchema = Data11.Map(
1080
+ Data11.Object({ epoch: Data11.Integer(), scale: Data11.Integer() }),
1081
+ SPIntegerSchema,
1082
+ { minItems: 0 }
1083
+ );
1084
+ var EpochToScaleToSum = EpochToScaleToSumSchema;
1085
+ var StabilityPoolContentSchema = Data11.Object({
1086
+ asset: Data11.Bytes(),
1087
+ snapshot: StabilityPoolSnapshotSchema,
1088
+ epochToScaleToSum: EpochToScaleToSumSchema
1089
+ });
1090
+ var StabilityPoolContent = StabilityPoolContentSchema;
1091
+ var AccountActionSchema = Data11.Enum([
1092
+ Data11.Literal("Create"),
1093
+ Data11.Object({
1094
+ Adjust: Data11.Object({
1095
+ amount: Data11.Integer(),
1096
+ outputAddress: AddressSchema
1097
+ })
1098
+ }),
1099
+ Data11.Object({ Close: Data11.Object({ outputAddress: AddressSchema }) })
1100
+ ]);
1101
+ var AccountAction = AccountActionSchema;
1102
+ var AccountContentSchema = Data11.Object({
1103
+ owner: Data11.Bytes(),
1104
+ asset: Data11.Bytes(),
1105
+ snapshot: StabilityPoolSnapshotSchema,
1106
+ request: Data11.Nullable(AccountActionSchema)
1107
+ });
1108
+ var AccountContent = AccountContentSchema;
1109
+ var SnapshotEpochToScaleToSumContentSchema = Data11.Object({
1110
+ asset: Data11.Bytes(),
1111
+ snapshot: EpochToScaleToSumSchema
1112
+ });
1113
+ var SnapshotEpochToScaleToSumContent = SnapshotEpochToScaleToSumContentSchema;
1114
+ var StabilityPoolDatumSchema = Data11.Enum([
1115
+ Data11.Object({
1116
+ StabilityPool: Data11.Object({ content: StabilityPoolContentSchema })
1117
+ }),
1118
+ Data11.Object({ Account: Data11.Object({ content: AccountContentSchema }) }),
1119
+ Data11.Object({
1120
+ SnapshotEpochToScaleToSum: Data11.Object({
1121
+ content: SnapshotEpochToScaleToSumContentSchema
1122
+ })
1123
+ })
1124
+ ]);
1125
+ var StabilityPoolDatum = StabilityPoolDatumSchema;
1126
+ var ActionReturnDatumSchema = Data11.Enum([
1127
+ Data11.Object({
1128
+ IndigoStabilityPoolAccountAdjustment: Data11.Object({
1129
+ spent_account: OutputReferenceSchema
1130
+ })
1131
+ }),
1132
+ Data11.Object({
1133
+ IndigoStabilityPoolAccountClosure: Data11.Object({
1134
+ closed_account: OutputReferenceSchema
1135
+ })
1136
+ })
1137
+ ]);
1138
+ var ActionReturnDatum = ActionReturnDatumSchema;
1139
+ var StabilityPoolRedeemerSchema = Data11.Enum([
1140
+ Data11.Object({ RequestAction: Data11.Object({ action: AccountActionSchema }) }),
1141
+ Data11.Object({
1142
+ ProcessRequest: Data11.Object({ requestRef: OutputReferenceSchema })
1143
+ }),
1144
+ Data11.Object({ AnnulRequest: Data11.Object({}) }),
1145
+ Data11.Object({ LiquidateCDP: Data11.Object({}) }),
1146
+ Data11.Object({ RecordEpochToScaleToSum: Data11.Object({}) }),
1147
+ Data11.Object({ UpgradeVersion: Data11.Object({}) })
1148
+ ]);
1149
+ var StabilityPoolRedeemer = StabilityPoolRedeemerSchema;
1150
+ function parseStabilityPoolDatum(datum) {
1151
+ return match3(Data11.from(datum, StabilityPoolDatum)).with({ StabilityPool: { content: P3.select() } }, (res) => res).otherwise(() => {
1152
+ throw new Error("Expected a Stability Pool datum.");
1153
+ });
1154
+ }
1155
+ function parseAccountDatum(datum) {
1156
+ return match3(Data11.from(datum, StabilityPoolDatum)).with({ Account: { content: P3.select() } }, (res) => res).otherwise(() => {
1157
+ throw new Error("Expected a StakingPosition datum.");
1158
+ });
1159
+ }
1160
+ function parseSnapshotEpochToScaleToSumDatum(datum) {
1161
+ return match3(Data11.from(datum, StabilityPoolDatum)).with({ SnapshotEpochToScaleToSum: { content: P3.select() } }, (res) => res).otherwise(() => {
1162
+ throw new Error("Expected a SnapshotEpochToScaleToSum datum.");
1163
+ });
1164
+ }
1165
+ function serialiseStabilityPoolDatum(d) {
1166
+ let cbor = Data11.to(d, StabilityPoolDatum);
1167
+ if ("StabilityPool" in d) {
1168
+ if (cbor.includes("bf")) {
1169
+ if (d.StabilityPool.content.epochToScaleToSum.size > 0) {
1170
+ cbor = cbor.replace(
1171
+ "bf",
1172
+ "a" + d.StabilityPool.content.epochToScaleToSum.size
1173
+ );
1174
+ cbor = cbor.replace("ffffff", "ffff");
1175
+ }
1176
+ }
1002
1177
  }
1178
+ return cbor;
1179
+ }
1180
+ function serialiseStabilityPoolRedeemer(params) {
1181
+ return Data11.to(params, StabilityPoolRedeemer);
1182
+ }
1183
+ var StabilityPoolParamsSchema = Data11.Object({
1184
+ assetSymbol: Data11.Bytes(),
1185
+ stabilityPoolToken: AssetClassSchema,
1186
+ snapshotEpochToScaleToSumToken: AssetClassSchema,
1187
+ accountToken: AssetClassSchema,
1188
+ cdpToken: AssetClassSchema,
1189
+ iAssetAuthToken: AssetClassSchema,
1190
+ versionRecordToken: AssetClassSchema,
1191
+ collectorValHash: Data11.Bytes(),
1192
+ govNFT: AssetClassSchema,
1193
+ accountCreateFeeLovelaces: Data11.Integer(),
1194
+ accountAdjustmentFeeLovelaces: Data11.Integer(),
1195
+ requestCollateralLovelaces: Data11.Integer()
1196
+ });
1197
+ var StabilityPoolParams = StabilityPoolParamsSchema;
1198
+ function castStabilityPoolParams(params) {
1199
+ return Data11.castTo(params, StabilityPoolParams);
1200
+ }
1201
+ var spPrecision = 1000000000000000000n;
1202
+ function mkSPInteger(value) {
1203
+ return { value: value * spPrecision };
1204
+ }
1205
+ function fromSPInteger(value) {
1206
+ return value.value / spPrecision;
1207
+ }
1208
+ function spAdd(a, b) {
1209
+ return { value: a.value + b.value };
1210
+ }
1211
+ function spSub(a, b) {
1212
+ return { value: a.value - b.value };
1213
+ }
1214
+ function spMul(a, b) {
1215
+ return { value: a.value * b.value / spPrecision };
1216
+ }
1217
+ function spDiv(a, b) {
1218
+ return { value: a.value * spPrecision / b.value };
1219
+ }
1220
+
1221
+ // src/scripts/stability-pool-validator.ts
1222
+ import {
1223
+ applyParamsToScript as applyParamsToScript4
1224
+ } from "@lucid-evolution/lucid";
1225
+
1226
+ // src/types/system-params.ts
1227
+ import { fromText as fromText5, toText } from "@lucid-evolution/lucid";
1228
+ function toSystemParamsAsset(asset) {
1229
+ return [
1230
+ { unCurrencySymbol: asset.currencySymbol },
1231
+ { unTokenName: toText(asset.tokenName) }
1232
+ ];
1233
+ }
1234
+ function fromSystemParamsAsset(asset) {
1235
+ return {
1236
+ currencySymbol: asset[0].unCurrencySymbol,
1237
+ tokenName: fromText5(asset[1].unTokenName)
1238
+ };
1239
+ }
1240
+
1241
+ // src/scripts/stability-pool-validator.ts
1242
+ var stabilityPoolValidator = {
1243
+ type: "PlutusV2",
1244
+ description: "",
1245
+ cborHex: "5939ed5939ea01000032323232323232322232323232323232323232323232322323232323225333018323232533301b3012301d37540022646464646464646464646464646464646464646464646464646464646464646464646464646464a646464646466608e6088056264a666090607e60946ea81184cc88c8c94ccc140c14c00854ccc140c14ccc074dd6181318279baa0333026304f3754604c609e6ea8c094c13cdd5000899299982699816a48115496e76616c6964206163636f756e742069706e757400300b3027305037540042a66609a6605a9201274163636f756e74206f776e6572206d757374207369676e20746865207472616e73636174696f6e003302e034375c604e60a06ea801054ccc134cc0b524011543616e6e6f74206d696e7420616e7920746f6b656e0000713302d49116496d70726f706572204163636f756e7420646174756d0032533304e304500113302e49011d4163636f756e74206f757470757420646f6573206e6f74206d6174636800333330133758602a60a26ea80d4c024cc14c0092f5c06014660a66012660a664646034660aa60ac004660aa60ac002660aa60ac60ae002660aa6034660aa01297ae04bd70182b00098289baa0054bd7025eb80cccc048cc044c098c088c144dd502699b80375a604a60a26ea8134dd6980318289baa04d375c605060a26ea8134dd7181398289baa0053023375a60a860a26ea801d300103d87a80001533304e304200113302e4911d4163636f756e74206f757470757420646f6573206e6f74206d6174636800333330133758602a60a26ea80d4c024cc14c0092f5c06014660a66012660a664646034660aa60ac004660aa60ac002660aa60ac60ae002660aa6034660aa01297ae04bd70182b00098289baa0054bd7025eb80cc044c098c088c144dd50269bad30063051375409a980103d87a800014a0609e6ea80185280a5014a0604c609e6ea8c094c13cdd50008b0b18288009998049bac3024304d3754062603c609a6ea812530103d87980002304f30503050305030503050305030503050305030503050001304e304b375408c2940c134c128dd501b099191919191919191919191919191929919982b982701d89919299982c982b000899191929998301831801099299982e982d182f9baa00113232533305f30563061375400226464a6660ca60d0004264a6660c46464a6660c860c260cc6ea800854ccc190c184c198dd5183518339baa00213304449138437265617465206163636f756e7420726571756573742063616e6e6f74206861766520616e206175746820746f6b656e20616c72656164790030613322333028002375c608060d26ea8004dd7181f98349baa0013756607a60ce6ea8c0f4c19cdd5003981c18339baa063001001133043491204163636f756e74206973206d697373696e6720616e206175746820746f6b656e00330243756607860cc6ea8c0f0c198dd5003181b98331baa0623036306537540042a6660c46608492011c496e76616c69642073746162696c69747920706f6f6c20696e707574003020303c3065375400e2a6660c4660849201314d697865642076657273696f6e73206265747765656e2073746162696c69747920706f6f6c20616e642072657175657374003375e607860ca6ea8c0f0c194dd5181d98329baa005303c30653754607860ca6ea8c0ecc194dd5003899821249234d75737420636f6e73756d65204163636f756e74205554784f20636f72726563746c790032323375e004603e660d201a97ae0304e0013300e00b3756603460ca6ea81245280a5014a060a60022c60cc00260c46ea800458c024c094c184dd5181b98309baa0013063306037540022c6602a00600a2c60c2002666032002606660ba6ea8165300103d8798000375860be60b86ea810054ccc164c1400044cc8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c88c8c94ccc1bcc1b0c1c4dd5000899191919299983b983d001099299983a1838983b1baa00113232533307a307d0021325332330783305849011854686520617373657420646f6573206e6f74206d61746368003001375c60a260f66ea803054ccc1e0cc1612401354f6e6c79207468652053746162696c69747920506f6f6c20616e6420746865204163636f756e742063616e20626520696e7075747300306c300d008153330783305849012a4d75737420636f6e73756d652053746162696c69747920506f6f6c205554784f20636f72726563746c790032323375e004606a660fe60a860fa6ea802d2f5c060c80026604860a460f66ea8018dd59818183d9baa05f13232533307a3071001153307b49012043616e6e6f742070726f6365737320616e20656d70747920726571756573742e0016132533307b30780021533307b3078307d375461020260fc6ea800c4c8c8c94ccc1f8cc1792411a4d757374206d696e7420616e206163636f756e7420746f6b656e00303b374c60ac60a46102026ea81f454ccc1f8cc1792401275265717565737420696e7075742063616e20636f6e7461696e206f6e6c792032206173736574730030723021304b375660ae6102026ea8c15cc20404dd50078a99983f1982f2490b4163636f756e74203e203000303e0011533307e3305e49012453746162696c69747920506f6f6c206f757470757420646f6573206e6f74206d61746368003232333330453758608e6106026ea819cc0eccc214040112f5c060786610a0260946610a0260946610a0260b46106026ea802ccc21404004cc21404dd319981a9bab3047308301375401660946610a0260a86106026ea8c164c20c04dd5005998428098299841809baa3059308301375401697ae03047308301375400297ae04bd7025eb80cc10ccccc110dd5982c9841809baa3059308301375401c6eb8c168c20c04dd503f9bae305a30830137540160066eb4c0e0c20c04dd503fa60103d879800032304a3308501308601001330850100233085013302d3047308301375460b26106026ea802ccc0c8cc0c4c0b8dd6981c1841809baa07f305a308301375460b26106026ea802c008c21c04c21c04c21c04004c20804dd5182c1841009baa00a3302b3057308101375460ae6102026ea8024c0b00044cc1792411d4163636f756e74206f757470757420646f6573206e6f74206d6174636800333330433758608a6102026ea8194c0e4cc20c040092f5c06074661060260726610602609066106026ea400ccc20c04c160c20404dd500499841809918249984200984280800998420098168011843009843008009840809baa30573081013754012661060298103d87a80004bd7025eb812f5c06608260ac60a46102026ea81f4cdc099b813032375660ae6102026ea8c15cc20404dd50079bad303630810137540fa60646eacc148c20404dd5032a60103d87a800014a029405280a5033303f375660ac6100026ea8c158c20004dd50071bae305730800137540f86eb8c15cc20004dd5004182b183f9baa3055307f37540146eb8c154c1f8dd5007800800899299983d983c001099299983e1838183f1baa0011323232325333084013087010021325333081013078308301375400226464a66610e02611402004264646464646464646464a66611a02660da9211854686520617373657420646f6573206e6f74206d61746368003016375c60ce6120026ea802c54ccc23404cc1b524011b4d757374206275726e20746865206163636f756e7420746f6b656e00304a374c60b060ca60c26120026ea82300454ccc23404cc1b524012453746162696c69747920506f6f6c206f757470757420646f6573206e6f74206d617463680033333052375860a86120026ea81d0c120cc248040412f5c06092661240260ae66124026460b066126026128020026612602004612a02612a020026120026ea80612f5c097ae0333305133050375660cc6120026ea8c198c24004dd500d982c8039bae30673090013754118026eb8c19cc24004dd500c19b8030590040034c103d87980001533308d013306d491524d7573742073656e642074686520616d6f756e7420696e20746865206163636f756e7420616e64207468652072656d61696e696e6720636f6c6c61746572616c206261636b20746f20746865206f776e65720033333052375860a86120026ea81d0c120cc248040452f5c0609266124026090661240260ce6120026ea80792f5c097ae033330513305033056375660cc6120026ea8c198c24004dd500f182c183298309848009baa08c013370266e0401c018c104dd598309848009baa074375c60ce6120026ea823004dd718339848009baa0183370200800698103d87a800013306d49011f4d757374207061792070726f746f636f6c2066656520636f72726563746c79003333302c375860a86120026ea81d0dd618339848009baa0743756608a6120026ea81d0dd718169848009baa08c0100614a029405280a5030563309101308f010013309101308e01001309301309301308f01375460ca611e026ea805cccc0a400400cc190c23804dd500b29998450099baf00230384800052000133025306c308d01375401000260bc6056008604a6606e60c26116026ea8c184c22c04dd500980199811198119bac3060308a0137540dc60d26114026ea821804004dd69844808011843808009919192999843809842009844809baa00213376060c06114026ea8004c23404c22804dd50010a9984400a492245706f6368546f5363616c65546f53756d206d6170206d697373696e67206974656d001630880100230880100133301d305d308701375401e6096610e026ea8060cccc07820c04dd7182f1843809baa00f37566096610e026ea803cdd6182e9843809baa06b301b0011630880100130840137540022c6056608e6106026ea8c164c20c04dd50008b18428080099981e9bac305730810137540ca602a6102026ea81f530103d87980003057308001375460ac6100026ea802cc20804c1fcdd5000801184080983f1baa003001132332232323253330840130870100213232533308601308901002132533308301307a308501375400226464a666112026118020042646464646464646464646464646464a66612802660e89211854686520617373657420646f6573206e6f74206d6174636800301d375c60dc612e026ea804054ccc25004cc1d124011d4163636f756e74206f757470757420646f6573206e6f74206d617463680033333059375860b6612e026ea81ecc13ccc26404c1b8c25c04dd51836984b809baa0224bd7018281984c8098279984c80982f1984c809837184b809baa0283309901306e309701375403e66132020106613202980103d87a80004bd7025eb812f5c0660ae60d860d0612e026ea824c04cdc099b813370260906eacc1b4c25c04dd51836984b809baa025375a60d6612e026ea824c04c120dd59834184b809baa07b3370066e04c120dd59836984b809baa01500c00b4c103d87a80001533309401330744911f4d757374207061792070726f746f636f6c2066656520636f72726563746c790033333033375860b6612e026ea81ecdd61837184b809baa07b37566098612e026ea81ecdd7181a184b809baa0930100b15333094013307449012453746162696c69747920506f6f6c206f757470757420646f6573206e6f74206d617463680033333059375860b6612e026ea81ecc13ccc2640405d2f5c060a0661320260bc661320260bc661320260dc612e026ea807ccc26404008cc26404dd3000a5eb812f5c097ae0333305833057375660da612e026ea8c1b4c25c04dd501119b81375a60d6612e026ea824c04030dd71837184b809baa09301375c60dc612e026ea807ccdc000480326103d87a8000153330940133074491244d7573742073656e6420617070726f7072696174652076616c756520746f206f776e6572003333305933099010154bd7018279984c8080c25eb80c140cc26404c178cc26404c1b8c25c04dd5012a5eb812f5c0a666128020142606a66e0403002c4cccc160c0d4cdc08060059bae306e3097013754126026eb8c1b8c25c04dd500f99b8130600090064c0103d87a800013307449011543616e6e6f74206d696e7420616e7920746f6b656e0004e14a029405280a5014a06660906eacc168c25804dd500f182e9984c009833984b009baa306c309601375403c661300260cc612c026ea8c1b0c25804dd500f25eb80c168c25804dd5000982e1984b808009984b808011984b809981f982c984a809baa306b309501375403a660886608660806eb4c1a4c25404dd504880800801184c80984c80984c80984a809baa306b309501375403a61280200461240200266605a00200460d06124026ea80694ccc238054ccc23804010528899baf001303c48000520001330293070309101375401460b400660546607460cc6120026ea8c198c24004dd500c181d80119182b998490098498080099849009981d18331848009baa006303b002309401309401001308f01375400aa6661160200220202660c202060ae605a60c8611c026ea8010c14003ccc090cc094dd618311846009baa070306b308c013754110020026eb4c22c04008c22404004c8c8c94ccc22404c21804c22c04dd5001099bb0001308f01308c0137540042a661140292012245706f6368546f5363616c65546f53756d206d6170206d697373696e67206974656d0016308a01002308a0100133301f305f3089013754022609a6112026ea8068cccc08021404dd718301844809baa0113756609a6112026ea8044dd6182f9844809baa06d301d00116308a0100130860137540022c605a6092610a026ea8c16cc21404dd50008b18438080099981f9bac305930830137540ce602e6106026ea81fd30103d879800016308501001330313758608a6102026ea8194c0e4cc20c040092f5c060ae6100026ea8c158c20004dd50059bad308101001308101308201001307d375461000260fa6ea8008c1ecdd50009826183d9baa00c14a02940dc79bae3051307a37540042940c1b800458c1ec004c1dcdd50008b180f181d183b1baa304c307637540022c60f0002666060002609460e86ea81c1300103d879800033041003304a30733754609460e66ea8c124c1ccdd5000983a98391baa0011633027001053375860e660e06ea8150c004004894ccc1c000452000130163300200230730012307030713071307130713071001253330693066306b3754002264646464646464646464646464646464646464646464646464646464a666112026118020042646464646464646464646464931820006181b007981a808181a00898198091819009981880a181800a981780b181700b981600c192999843009841808008991929998460098478080109924c605e0022c611a020026112026ea806854ccc21804c1f40044c8c94ccc23004c23c040084c926533308801308501308a01375400226464a66611c026122020042649318180008b1847808009845809baa0011616308d0100130890137540342c610e026ea806458c22804004c22804008c94ccc21c04c2180400454ccc20c04c1e8c214040045288a999841809840009842808008a5016163754611002002611002004610c02002610c0200461080200261080200461040200261040200461000200261000200460fc00260fc00460f800260f800460f400260f400460f000260f000460ec00260ec00460e800260e800460e400260e40046eb8c1c0004c1b0dd50008b1111919bb032303633071307200133071533306c337106eb4c118c1bcdd50011bad3046306f37546603c608a60de6ea8010c0692080a8d6b90714c0105d8799f00ff00100230733073001306e375400864a6660d860c660dc6ea8004530103d87a80001303633071375064601e6603e6603c6603466038002606860e06ea8014cc07ccc070c94ccc1b8c194c1c0dd500088010983a18389baa0013301200430373307230413070375400a660e46ea0c05cdd6982018381baa0054bd70000980da410151ad720e608c60e06ea8014c11cc1c0dd5002983918379baa0014bd7019808001181a99838181f98371baa00333070303e306e375400697ae0533306a337106eb4c0f8c1b4dd50011bad303e306d3754006298105d8799f00ff001533306a33710900119b81375a607a60da6ea800cdd6981e98369baa00214c0105d8799f00ff001533306a337106eb4c0f4c1b4dd50011bad303d306d375400626603866036608660da6ea8008c110c1b4dd5001981a198379ba8337046eb4c110c1b4dd5182218369baa00248202a35ae41d2f5c026603866036608660da6ea8008c110c1b4dd5001982218369baa00222223302032333001001323300100100322533307100114bd6f7b630099192999837983318389baa001133004004002133074323376060ec00260ec60ee0026eb0c1d4c1c8dd500099802002001192999837998181bab304830723754002606c60e46ea80244c94ccc1c0c190c1c8dd500089919299983b183c801099299983999b8f375c609860ec6ea80080304c0f4cc1e0c8dd39983c983b0009983c983b800a5eb80cdd81826983b1baa002304c3076375400497ae015330744912d45706f6368546f5363616c65546f53756d2072656620696e7075747320686176652077726f6e6720617373657400163063001163077001307337540022c6034606c60e46ea8004530103d87a800030473071375460e800460e800297adef6c60222533307100210011333003003307400233023001375660de60e600400444a6660ce66e2400520001480004dd6982098351baa30313306c375066e0ccdc11bad3041306a37546062660d86ea0cdc199b82375a608260d46ea8c0c4cc1b0dd4000a5eb80dd6982098351baa0024820225e92f5c0904044bd1bad3041306a37546062660d86ea0cdc12419002904044bd25eb812f5c044607260d26ea8c0fcc1a4dd5191929998361837801099190012999834983318359baa00113232323232323232323232325333079307c0021324994ccc1d4c1c8c1dcdd50048991919191919191919191919191919191919191929998468098480080109924c60600162c6eb4c23804004c23804008dd69846008009846008011bad308a01001308a01002375a6110020026110020046eb4c21804004c21804008c21004004c21004008dd69841008009841008011bad308001001308001002375a60fc00260fc0046eb4c1f0004c1e0dd50048b0b1bad307a001307a002375a60f000260f00046eb4c1d8004c1d8008dd6983a000983a001183900098390011bad3070001306c37540022c6026605e60d66ea8c104c1acdd50008b1836800999812801000a6103d8798000253330643024375a607c60ce6ea800440045300105d8799f00ff00222323376066026006002a6660cc60c60082608060d26ea80084cc05cc100c1a4dd500119809980a240046603000200660260064444464a6660ce604e004264a6660d06464608c00464a6660d460ce0022a6660dc60da6ea8008526161533306a30610011533306e306d37540042930b0a999835182f0008a99983718369baa00214985858c1acdd50009980a182118359baa00100513333302d00730233306d30323306d0023306d4c103d87a80004bd7025eb8130107d87b9fd87980ff003302b3756608260d66ea8c104c1acdd5000801a60103d879800014a064a6660d80022a660d2921284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400161533306c306f0011306e00115330694901284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400163303800500114a26042660d66ea40092f5c0460ce60d060d060d060d060d060d060d00024666076911004881000012337066eb4c0e4c188dd5000a41010141ede959b7c036600200244a6660c400229000098041980100118328009119299982f182a98301baa00114c103d87a800013028330633061323376060ca00260ca60cc0026eb0c190c184dd5000a5eb80cc0500088cdd798300008011299982d982c182e9baa00113232323253330633066002149858dd7183200098320011bae3062001305e37540022c4a6660b460ae60b86ea80044c8c94ccc180c18c00852616375a60c200260ba6ea800458c17cc170dd502b8a50305a37540ac60ba60b46ea811854ccc15cc12c0ec54ccc15cc138c164dd502a89919299982c982b182d9baa001132533305e30613302b3758606860ba6ea8104c0d0c174dd50008a99982d1981d249415265717565737420616e6e756c6d656e74207472616e73616374696f6e206d757374206265207369676e6564206279207468652072657175657374206f776e6572003303b041375c606860ba6ea800c54ccc168cc0e924011543616e6e6f74206d696e7420616e7920746f6b656e0001413232533305c3053001153305d491185265717565737420697320616c726561647920656d7074790016132533305d305a0021533305d305a305f375460c660c06ea800c52880080089981e2491d4163636f756e74206f757470757420646f6573206e6f74206d6174636800333330213758604660be6ea810cc05ccc18400d2f5c06030660c2602e660c264646050660c660c8004660c660c8002660c660c860ca002660c698103d87a80004bd701832000982f9baa0054bd7025eb80c0d0c0c0c17cdd502da60103d87a8000305d3754002605c60ba6ea800c5280a50163033305c3754606460b86ea8c17cc170dd50008b198089bac3032305b375407e07a60ba60b46ea815452809919299982c982301e8a99982c982b182d9baa05713232323232533305e305b30603754002264646464a6660cc60d2004264a6660c660c060ca6ea80044c8c94ccc1a4c1b000854ccc194c188c19cdd5000899191919191919192999838983a001099191919299983a983c0010991919299983a1982a2493f45706f6368546f5363616c65546f53756d206d617020697320746f6f206c617267652c20757365205265636f726445706f6368546f5363616c65546f53756d003371260386eacc0ecc1dcdd500da40142a6660e8660a892131694173736574206f662073746162696c69747920706f6f6c206d757374206d6174636820694173736574206f6620636470003371e0186eb8c138c1dcdd500d8a99983a1982a2491c43445020696e707574206d757374206265206c6971756964617465640032323375e004980103d87f800032533307630730011323232323232533308001308301002149858dd69840808009840808011bad307f001307f002375a60fa00260f26ea800854ccc1d8c1b40044c8c94ccc1f0c1fc00852616375a60fa00260f26ea800854ccc1d8c1a80044c8c94ccc1f0c1fc00852616375a60fa00260f26ea800854ccc1d8c18c0044c8c94ccc1f0c1fc00852616375a60fa00260f26ea800854ccc1d8c18800454ccc1e8c1e4dd50010a4c2c2a6660ec66e1d200a00113232533307c307f002132498c19800458c1f4004c1e4dd50010a99983b19b874803000454ccc1e8c1e4dd50010a4c2c2a6660ec66e1d200e0011533307a307937540042930b0a99983b19b874804000454ccc1e8c1e4dd50010a4c2c2c60ee6ea8004cc080c138c1dcdd50099bab302c307737540b62a6660e8660a89211c53746162696c697479506f6f6c206f7574707574206d697373696e6700330353756609a60ee6ea8c134c1dcdd500b1826983b9baa07313305449011f496e636f72726563742053746162696c69747920506f6f6c204f7574707574003375e607660ee6ea8010c0c0cc1e4c0f8cc1e4c0f8cc1e4c138c1dcdd500d9983c8011983c9ba60014bd7025eb812f5c029405280a5014a06eacc1d8008c1d0004c8c8c8c8c8c8c8cdd8299983c0008991919182299840009840808019984000984080801198400098408080099840009ba83025375a609e60fc6ea8028c20804c20804004c20404004c20004004c1ecdd52611dd8799fd8799f1b0de0b6b3a7640000ffd8799f00ffd8799f00ff0000ff00130423307d0033307d330273051307b375400e00c660fa004660fa609860f66ea801ccc1f4dd419b80375a609660f66ea801d4ccc1e0010520021480012f5c06e98c94ccc1e40084ccc0b8004c10ccc1f8dd418119bad304d307c3754010660fc9810100004bd701813a40002a6660f200a266605c0026086660fc609a60f86ea8020cc1f8dd418119bad304c307c375401097ae0003100133302d3756607e60f66ea807cc108cc1f4c130c1ecdd50039983e9825983d9baa0074bd7000119b89375a60a260f46ea8009200033023303d3079375400a660506604e604866e04c0a8dd59827983c9baa006302a3756609e60f26ea8c13cc1e4dd500c1828183c9baa005304f3079375400a6604c607e660f46ea0cdc1299983a8008a410151ad720e290011bad304f30783754609e60f06ea80112f5c000466e20dd69827183b9baa33025304e307737540060029040546b5c83998111810a40046604a002609860ec6ea8008c080c0f8ccc0d0c140dd59822983a9baa059375c609860ea6ea81c4dd71826183a9baa019304a307437540302c60ec002660440266054660e802097ae032533306f306c0011323232325333077307a002149858dd6983c000983c0011bad3076001307237540062a6660de60cc002264646464a6660ee60f40042930b1bad30780013078002375a60ec00260e46ea800c58c1c0dd5001180e8038b183900098390011bad30700013070002375c60dc00260dc00460d800260d06ea80045858c1a8004c198dd50008b1806981498329baa303b306537540022c60ce00266603e00a606660c66ea817d300103d87a8000303930623754607060c46ea8004c190c184dd50008b1980b0010211bac306230633063002375860c200260ba6ea8104c17cc170dd502b8a5015333059304503d153330593056305b37540ae26464646464a6660bc60b660c06ea80044c8c8c94ccc194c1a00084c8c8c94ccc190cc11124011d496e76616c696420696e707574206265696e672076616c696461746564003022303e306737540082a6660c866088920111436f7272656374205350206f75747075740033333029008301f330690064bd70181019834981719834981719834981f18339baa00b33069303d30673754016660d26e98cc1a40092f5bded8c097ae04bd7025eb80dd5981e98339baa303d3067375400898103d87980001533306433044491264d696e747320612073696e676c652065706f6368546f5363616c65546f53756d20746f6b656e003021374c6078605660ce6ea818c54ccc190cc111240129436f727265637420736e617073686f742065706f6368546f5363616c65546f53756d206f75747075740033333029008301f330690064bd701810198349810198349817198349ba600133069303e3067375401697ae04bd7025eb80c0f0c0acc19cdd5031a60103d87a8000133044490119736e617073686f74206d6170206973206e6f7420656d707479003330643061300c0014a09445280a5014a02940dd598330011919bb030690013069306a001375860c80026464646464a6660d460da006266ec0dd3998359834000998359834800a5eb80dd30010b18358011bab3067002375660ca00264660020026eacc0a8c198dd50051129998340008a5ef6c60101a0000101a00013232323253330683232533306a3370e6eb4c1c0008dd6981f18369baa00913370e0026eb4c0f4c1b4dd50048a50375a60de60e000260d66ea8c1a80104cdd81ba63306d004002374c002266ec0dd30011ba63306d004001375660d40046eacc1a0004cc00c00cc1b0008c1a8004c0e8c190dd50040b183300099980f002181c18311baa05e4c103d8798000303830613754606e60c26ea8c190c184dd50008b1980b0010211bac306230633063002375860c200260ba6ea8104c17cc170dd502b8a50133332323222232323232325333064306130663754002264a6660ca60b860ce6ea80044c8c8c94ccc1b0c1bc0084c8c8c94ccc1acc1a0c1b4dd500089982599808198381ba93730921084d697373696e6720003307037526e6003ccc1c0dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd70249003304e30113049009375c60e260dc6ea800454cc1b0cc040cc1c0dd49b98491084d697373696e6720003307037526e6003ccc1c0dd49b9849010d20757067726164652070617468004bd70249001632533306b3062306d3754002298103d87a8000130353307037526eb8c1b8c8cdd81839000983918398009bac3071306e375400297ae0330213756608660da6ea80088cdc79bae306d00100653330693066306b3754002264646464a6660e260e800426493198338009191bae3072002375c60e00022c6eacc1c8004c1c8008dd6983800098361baa001163013302f306b3754608260d66ea800458c1b4004ccc09401402130103d8798000375c60d660d06ea800458c0f8c19cdd5181f18339baa303d3067375460d460ce6ea800458cc070dd618348020241bab3068306930693069002375860ce00260ce00260c46ea800888dcc99191998008008022441002225333065002100113233300400430690035333062305f371a00426e600044cdc500119b8a00537300026e64dd718338011b98001300100122533305f00114bd70099830182e9830800998010011831000a490d53746162696c697479506f6f6c003033305c375408460be60c060c060c060c060c060c060b86ea8160c004004894ccc1740045200013003330020023060001370090011299982b1825182c1baa0011305c305937540022a660ae9201134e6f7420616e20696e6c696e6520646174756d001622325333057305430593754002260ba60b46ea800454cc16124117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533305d00114c0103d87a80001323232533305c3375e00c60bc0062604c660c200297ae0133005005002305e0023061002305f00130113305b0024bd7011180f9982d1ba8337006eb4c0bcc160dd50011bad302f3058375400297ae02301d33058375066e08005208080a0f6f4acdbe01b4bd7011180e9982c1ba8337026eb4c0b4c158dd50011bad302d3056375400297ae02325333052304f001132325333058305b002149858dd7182c800982a9baa00215333052304900115333056305537540042930b0b18299baa00122301b33056375066e0ccdc11bad302b305437540046eb4c0acc150dd5000a41010141ede959b7c03697ae022301a33055375066e0ccdc11bad302a30533754004904040507b7a566df00d9bad302a3053375400297ae022330210023017001233300f001488100488100222533304e533304e304b305037546600a006466ebcc14400400c5288a501323300100100422533305400114bd6f7b63009982a9919299982919baf00100613376000200a200460a600260ac0026600400460ae002266008006660a666ec00080052f5bded8c044646600200200644a6660a400220062660a660a80026600400460aa00244646600200200644a6660a20022980103d87a800013232533304f30050021301933054374e660a860a2004660a860a400497ae04bd70099802002000982a8011829800918279828182818281828182818281828182818280009119198008008019129998278008a6103d87a800013232533304d3375e604e60a06ea80080144c05ccc1480092f5c026600800800260a600460a2002600698101a000374a90011ba548010dd79ba630213756602c608c6ea80a8dd7813911191980b80211801180f98249baa0015333044304130463754002246600c6eacc078c120dd50008018918029998039bab301e304837540026eb8c07cc120dd50019bae301e304837540066e212000223038333003002375c603660886ea8004dd7180d18221baa0012223253330423039304437540022900009bad30483045375400264a666084607260886ea8004530103d87a80001323300100137566092608c6ea8008894ccc120004530103d87a8000132323253330473371e00e6eb8c12400c4c044cc130dd4000a5eb804cc014014008dd698248011826001182500099198008008021129998238008a6103d87a8000132323253330463371e00e6eb8c12000c4c040cc12cdd3000a5eb804cc014014008dd59824001182580118248009119998018012450048810000122225333040303d001100413333300f0040033232002323300100100222533304700114984c94ccc120004526132325333046304330483754660466eb8c120c130010dd71824001099802802998258010008a99823a49326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016304c002304a001304a00133045337606ea4008dd4000a5eb7bdb180888c94ccc110c048004530103d87a80001300e33049374c00297ae033333013001005004222325333047304400114c103d87a8000130113304c375000297ae03370000200404003a4444464660020026602600c601200a44a66608c00229404c94ccc10cc94ccc110cdd7980598239baa001007132533304900114a22a66609260980022646464a666090604e6eb8c13800c54ccc120c09c00454ccc120c114c128dd50048a9998241807001099b89002482026fb808528098070010a5014a06eb8c134c138008dd69826182698268009bac304b00114a060226601a6eacc074c11cdd500098078030a50304900214a226600600600260920026e2520002304030413041001253330393036303b3754002264466ebcc054c0f8dd5180a981f1baa001002303f303c3754002264466ebcc054c0f8dd5000801181f981e1baa00122323330010010030022225333040002100113233300400430440033333300c002375c607e0026eacc100004888c94ccc104c03c004530103d87a80001300b33046374c00297ae03233300100100300222253330470021001132333004004304b00333333014002375c608c0026eb4c11c004888c94ccc120c1140045300103d87a8000130123304d375000297ae033700004002042609200403460840046e9520002323300100100222533303c00114bd6f7b6300991981f19bb037526eb8c0ec004dd319198008009bab303d00222533303f00114bd6f7b6300991982099bb037526eb8c0f8004dd418041bad303f0013300300330430023041001330030033040002303e001370290001191980080080111299981d0008a5eb804c8ccc888c8cc00400400c894ccc100004400c4c8cc108dd3998211ba90063304237526eb8c0fc004cc108dd41bad30400014bd7019801801982200118210009bae30390013756607400266006006607c00460780024a66606e002294452811111191980080080311299981e00089981e99bb0375200c6e980152f5bded8c0264646464a66607860306600e01400426608266ec0dd48051ba60090051533303c3371e014004264a66607a6074607e6ea80044cc108cdd81ba900b304330403754002008200866601001401200226608266ec0dd48011ba6001330060060033756607c0066eb8c0f0008c100008c0f800488888c8cc004004018894ccc0ec0044cc0f0cdd81ba9006375000a97adef6c60132323232533303b30173300700a002133040337606ea4028dd40048028a99981d99b8f00a002132533303c3039303e375400226608266ec0dd48059821181f9baa001004100433300800a009001133040337606ea4008dd4000998030030019bad303d003375c6076004607e004607a0024466006004466ebcc030c0d4dd51806181a9baa300b3035375400200444646600200200644a66606c002297ae0132325333034300500213303900233004004001133004004001303a00230380012303430353035303530350012303330343034303400123300248000004894ccc0b0cdc40008010801080091818181898189818981898189818981898189818981880091998021bae3003302c37540026eb8c008c0b0dd5000a40044605c605e0024605a002444a666050604a002297adef6c6013232330010014bd6f7b63011299981780089981819bb0375200c6e9800d2f5bded8c0264646464a66605e60166601801400426606866ec0dd48051ba60070051533302f3371e01400426606866ec0dd48051ba6007003133034337606ea4008dd3000998030030019bab3031003375c605e00460660046062002646600200297adef6c6022533302e00113302f337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0b8c028cc02c0200084cc0cccdd81ba9008375000e00a2a66605c66e3c0200084cc0cccdd81ba9008375000e00626606666ec0dd48011ba800133006006003375a60600066eb8c0b8008c0c8008c0c0004dd7a6103d879800022533302533720004002298103d8798000153330253371e0040022980103d87a800014c103d87b80002323300100100222533302900114bd6f7b63009919191929998149804001080189981719bb037520046e98004cc01801800cdd598158019bae3029002302d002302b001371e911002253330223330220014a094454cc08c0084004400488cc010dd6180198121baa002001230253026302630263026302630263026302600122323300100100322533302500114a0264a66604466e3cdd718140010020a511330030030013028001301e37540166042603c6ea800458c080c084008c07c004c06cdd50008a4c26cac600200a464a66602e602800226464a66603a60400042649318060008b180f000980d1baa00215333017300e00113232533301d3020002132498c01c00458c078004c068dd50010a99980b98058008a99980d980d1baa00214985854ccc05cc01000454ccc06cc068dd50010a4c2c2a66602e60060022a66603660346ea800852616153330173370e90050008a99980d980d1baa00214985858c060dd50009b8748020dc3a400c4a6660266020602a6ea80044c8c8c8c94ccc06cc0780084c926533301730143019375400626464a66603a60400042930b1bae301e001301a37540062c2c6eb4c070004c070008c068004c058dd50008b192999808980700089919299980b980d00109924c60160022c603000260286ea803c54ccc044c0200044c8c94ccc05cc0680084c92630050011630180013014375401e2a666022600a00226464a66602e60340042649318020008b180c000980a1baa00f163012375401c4a666020601a60246ea80044c8c8c8c94ccc060c06c0084c9263300e00323230123019002300e301700116375c603200260320046eacc05c004c04cdd50008b12999807980618089baa00113232323232323232533301b301e00213232498c94ccc064c0580044c8c94ccc07cc0880084c926300e001163020001301c37540062a66603260200022a66603a60386ea800c5261616301a375400460240062c60380026038004603400260340046eb8c060004c060008dd7180b00098091baa00116232533300f300c00115333013301237540042930b0a9998079803000899191919299980b980d00109924c60100022c603000260300046eb4c058004c048dd50010a999807980180089919299980a980c00109924c600c0022c602c00260246ea800858c040dd50009b874801094ccc030c024c038dd5000899191919299980a180b8010991924c64a666024601e00226464a66603060360042649319299980a980900089919299980d980f00109924c601a0022c603800260306ea800854ccc054c0300044c8c8c8c8c8c94ccc07cc08800852616375a604000260400046eb4c078004c078008dd6980e000980c1baa00216301637540022c6032002602a6ea800c54ccc048c02400454ccc058c054dd50018a4c2c2c60266ea8008c01800c58c054004c054008c04c004c03cdd50008b11929998061804800899192999809180a8010a4c2c6eb8c04c004c03cdd50010a9998061801800899192999809180a8010a4c2c6eb8c04c004c03cdd50010b18069baa001370e900112999804980318059baa00113232323232325333013301600213232498cc0280088c8c038c054008c028c04c004c02800c58dd5980a000980a001180900098090011bae3010001300c37540022c4a666010600a60146ea80044c8c8c8c94ccc040c04c00852616375a602200260220046eb4c03c004c02cdd50008b1119198008008019129998070008a4c264660060066024004600660200024a66600c600660106ea80044c8c8c8c8c8c8c8c8c8c94ccc050c05c0084c8c8c926300e007300d008300c00916375a602a002602a0046eb4c04c004c04c008c044004c044008c03c004c03c008c034004c024dd50008b12999802980118039baa00113232533300b300e002149858dd6980600098041baa00116370e90002b9a5738aae7555cf2ab9f5740ae855d11"
1246
+ };
1247
+ var mkStabilityPoolValidatorFromSP = (params) => {
1248
+ return {
1249
+ type: stabilityPoolValidator.type,
1250
+ script: applyParamsToScript4(stabilityPoolValidator.cborHex, [
1251
+ castStabilityPoolParams({
1252
+ assetSymbol: params.assetSymbol.unCurrencySymbol,
1253
+ stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
1254
+ snapshotEpochToScaleToSumToken: fromSystemParamsAsset(
1255
+ params.snapshotEpochToScaleToSumToken
1256
+ ),
1257
+ accountToken: fromSystemParamsAsset(params.accountToken),
1258
+ cdpToken: fromSystemParamsAsset(params.cdpToken),
1259
+ iAssetAuthToken: fromSystemParamsAsset(params.iAssetAuthToken),
1260
+ versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
1261
+ collectorValHash: params.collectorValHash,
1262
+ govNFT: fromSystemParamsAsset(params.govNFT),
1263
+ accountCreateFeeLovelaces: BigInt(params.accountCreateFeeLovelaces),
1264
+ accountAdjustmentFeeLovelaces: BigInt(
1265
+ params.accountAdjustmentFeeLovelaces
1266
+ ),
1267
+ requestCollateralLovelaces: BigInt(params.requestCollateralLovelaces)
1268
+ })
1269
+ ])
1270
+ };
1003
1271
  };
1004
1272
 
1005
- // src/scripts/interest-oracle-validator.ts
1006
- var _interestOracleValidator = {
1273
+ // src/helpers/stability-pool-helpers.ts
1274
+ var newScaleMultiplier = 1000000000n;
1275
+ function getSumFromEpochToScaleToSum(e2s2s, epoch, scale) {
1276
+ for (const [key, value] of e2s2s.entries()) {
1277
+ if (key.epoch === epoch && key.scale === scale) {
1278
+ return value;
1279
+ }
1280
+ }
1281
+ return void 0;
1282
+ }
1283
+ function setSumInEpochToScaleToSum(e2s2s, epoch, scale, sum) {
1284
+ const map = /* @__PURE__ */ new Map();
1285
+ for (const [key, value] of e2s2s.entries()) {
1286
+ if (!(key.epoch === epoch && key.scale === scale)) {
1287
+ map.set(key, value);
1288
+ }
1289
+ }
1290
+ map.set({ epoch, scale }, sum);
1291
+ return map;
1292
+ }
1293
+ function getAccountReward(account, e2s2s) {
1294
+ const s1 = getSumFromEpochToScaleToSum(e2s2s, account.epoch, account.scale);
1295
+ if (!s1) throw new Error("No scale found for epoch and scale");
1296
+ const s2 = getSumFromEpochToScaleToSum(e2s2s, account.epoch, account.scale + 1n) ?? s1;
1297
+ const a1 = spSub(s1, account.sumVal);
1298
+ const a2 = spDiv(spSub(s2, s1), mkSPInteger(newScaleMultiplier));
1299
+ return spDiv(spMul(spAdd(a1, a2), account.depositVal), account.productVal);
1300
+ }
1301
+ function getAccountFund(pool, account) {
1302
+ let fund = spDiv(
1303
+ spMul(account.depositVal, pool.productVal),
1304
+ account.productVal
1305
+ );
1306
+ if (pool.epoch > account.epoch) fund = mkSPInteger(0n);
1307
+ if (pool.scale - account.scale > 1n) fund = mkSPInteger(0n);
1308
+ if (pool.scale > account.scale)
1309
+ fund = spDiv(spMul(account.depositVal, pool.productVal), {
1310
+ value: account.productVal.value * newScaleMultiplier
1311
+ });
1312
+ if (fund.value < spDiv(account.depositVal, mkSPInteger(1000000000n)).value)
1313
+ return mkSPInteger(0n);
1314
+ return fund;
1315
+ }
1316
+ function adjust(pool, account, e2s2s) {
1317
+ const newAccountSnapshot = {
1318
+ ...pool,
1319
+ depositVal: getAccountFund(pool, account)
1320
+ };
1321
+ const accountReward = fromSPInteger(getAccountReward(account, e2s2s));
1322
+ return [newAccountSnapshot, accountReward];
1323
+ }
1324
+ function findEpochToScaleToSum(snapshotEpochToScaleToSumTokenRef1, snapshotEpochToScaleToSumTokenRef2) {
1325
+ let ess1;
1326
+ try {
1327
+ ess1 = parseSnapshotEpochToScaleToSumDatum(
1328
+ snapshotEpochToScaleToSumTokenRef1.datum
1329
+ ).snapshot;
1330
+ } catch (_) {
1331
+ ess1 = parseStabilityPoolDatum(
1332
+ snapshotEpochToScaleToSumTokenRef1.datum
1333
+ ).epochToScaleToSum;
1334
+ }
1335
+ const ess1Ref = {
1336
+ utxo: snapshotEpochToScaleToSumTokenRef1,
1337
+ e2s2s: ess1
1338
+ };
1339
+ if (snapshotEpochToScaleToSumTokenRef2) {
1340
+ const ess2 = parseSnapshotEpochToScaleToSumDatum(
1341
+ snapshotEpochToScaleToSumTokenRef2.datum
1342
+ );
1343
+ const ess2Ref = {
1344
+ utxo: snapshotEpochToScaleToSumTokenRef2,
1345
+ e2s2s: ess2.snapshot
1346
+ };
1347
+ return [ess1Ref, ess2Ref];
1348
+ }
1349
+ return [ess1Ref, void 0];
1350
+ }
1351
+ function adjustmentHelper(spESTSTokenRef1, spESTSTokenRef2, pool, e2s2s, account) {
1352
+ let accumulatedEpochToScaleToSum;
1353
+ let refInputs;
1354
+ const value = getSumFromEpochToScaleToSum(
1355
+ e2s2s,
1356
+ account.epoch,
1357
+ account.scale
1358
+ );
1359
+ if (value) {
1360
+ accumulatedEpochToScaleToSum = e2s2s;
1361
+ refInputs = [];
1362
+ } else {
1363
+ const [ess1, ess2] = findEpochToScaleToSum(
1364
+ spESTSTokenRef1,
1365
+ spESTSTokenRef2
1366
+ );
1367
+ if (ess2) {
1368
+ accumulatedEpochToScaleToSum = new Map([
1369
+ ...Array.from(ess1.e2s2s.entries()),
1370
+ ...Array.from(ess2.e2s2s.entries()),
1371
+ ...Array.from(e2s2s.entries())
1372
+ ]);
1373
+ refInputs = [ess1.utxo, ess2.utxo];
1374
+ } else {
1375
+ accumulatedEpochToScaleToSum = new Map([...Array.from(ess1.e2s2s.entries()), ...Array.from(e2s2s.entries())]);
1376
+ refInputs = [ess1.utxo];
1377
+ }
1378
+ }
1379
+ const [newAccountSnapshot, accountReward] = adjust(
1380
+ pool,
1381
+ account,
1382
+ accumulatedEpochToScaleToSum
1383
+ );
1384
+ return [newAccountSnapshot, accountReward, refInputs];
1385
+ }
1386
+ function updatePoolSnapshotWithdrawalFee(withdrawalFeeAmount, newPoolDepositExcludingFee, pool) {
1387
+ const newPoolDepositVal = spAdd(
1388
+ newPoolDepositExcludingFee,
1389
+ withdrawalFeeAmount
1390
+ );
1391
+ const newPoolProduct = withdrawalFeeAmount.value === 0n ? pool.productVal : spMul(
1392
+ pool.productVal,
1393
+ spAdd(
1394
+ mkSPInteger(1n),
1395
+ spDiv(withdrawalFeeAmount, newPoolDepositExcludingFee)
1396
+ )
1397
+ );
1398
+ return [newPoolDepositVal, newPoolProduct];
1399
+ }
1400
+
1401
+ // src/helpers/indigo-helpers.ts
1402
+ function calculateFeeFromPercentage2(feePercentage, amount) {
1403
+ if (amount < 0) {
1404
+ return 0n;
1405
+ }
1406
+ return ocdDiv(ocdMul({ getOnChainInt: amount }, feePercentage), {
1407
+ getOnChainInt: 100n * OCD_DECIMAL_UNIT
1408
+ }).getOnChainInt;
1409
+ }
1410
+
1411
+ // src/contracts/stability-pool.ts
1412
+ var StabilityPoolContract = class {
1413
+ static async createAccount(asset, amount, params, lucid) {
1414
+ const [pkh, _skh] = await addrDetails(lucid);
1415
+ const minLovelaces = BigInt(
1416
+ params.stabilityPoolParams.accountCreateFeeLovelaces + params.stabilityPoolParams.requestCollateralLovelaces
1417
+ );
1418
+ const datum = {
1419
+ Account: {
1420
+ content: {
1421
+ owner: pkh.hash,
1422
+ asset: fromText6(asset),
1423
+ snapshot: {
1424
+ productVal: { value: 0n },
1425
+ depositVal: { value: 0n },
1426
+ sumVal: { value: 0n },
1427
+ epoch: 0n,
1428
+ scale: 0n
1429
+ },
1430
+ request: "Create"
1431
+ }
1432
+ }
1433
+ };
1434
+ return lucid.newTx().pay.ToContract(
1435
+ credentialToAddress4(lucid.config().network, {
1436
+ hash: validatorToScriptHash4(
1437
+ mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
1438
+ ),
1439
+ type: "Script"
1440
+ }),
1441
+ { kind: "inline", value: serialiseStabilityPoolDatum(datum) },
1442
+ {
1443
+ lovelace: minLovelaces,
1444
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: amount
1445
+ }
1446
+ ).addSignerKey(pkh.hash);
1447
+ }
1448
+ static async adjustAccount(asset, amount, accountUtxo, params, lucid) {
1449
+ const [pkh, _] = await addrDetails(lucid);
1450
+ const myAddress = await lucid.wallet().address();
1451
+ const stabilityPoolScriptRef = await scriptRef(
1452
+ params.scriptReferences.stabilityPoolValidatorRef,
1453
+ lucid
1454
+ );
1455
+ const request = {
1456
+ Adjust: {
1457
+ amount,
1458
+ outputAddress: addressFromBech32(myAddress)
1459
+ }
1460
+ };
1461
+ const oldAccountDatum = parseAccountDatum(
1462
+ accountUtxo.datum
1463
+ );
1464
+ const newAccountDatum = {
1465
+ ...oldAccountDatum,
1466
+ request
1467
+ };
1468
+ const redeemer = {
1469
+ RequestAction: {
1470
+ action: request
1471
+ }
1472
+ };
1473
+ return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
1474
+ credentialToAddress4(lucid.config().network, {
1475
+ hash: validatorToScriptHash4(
1476
+ mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
1477
+ ),
1478
+ type: "Script"
1479
+ }),
1480
+ {
1481
+ kind: "inline",
1482
+ value: serialiseStabilityPoolDatum({
1483
+ Account: {
1484
+ content: newAccountDatum
1485
+ }
1486
+ })
1487
+ },
1488
+ {
1489
+ lovelace: BigInt(
1490
+ params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1491
+ ),
1492
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
1493
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: amount
1494
+ }
1495
+ ).addSignerKey(pkh.hash);
1496
+ }
1497
+ static async closeAccount(accountUtxo, params, lucid) {
1498
+ const [pkh, _] = await addrDetails(lucid);
1499
+ const myAddress = await lucid.wallet().address();
1500
+ const stabilityPoolScriptRef = await scriptRef(
1501
+ params.scriptReferences.stabilityPoolValidatorRef,
1502
+ lucid
1503
+ );
1504
+ const request = {
1505
+ Close: {
1506
+ outputAddress: addressFromBech32(myAddress)
1507
+ }
1508
+ };
1509
+ const oldAccountDatum = parseAccountDatum(
1510
+ accountUtxo.datum
1511
+ );
1512
+ const newAccountDatum = {
1513
+ ...oldAccountDatum,
1514
+ request
1515
+ };
1516
+ const redeemer = {
1517
+ RequestAction: {
1518
+ action: request
1519
+ }
1520
+ };
1521
+ return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
1522
+ credentialToAddress4(lucid.config().network, {
1523
+ hash: validatorToScriptHash4(
1524
+ mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
1525
+ ),
1526
+ type: "Script"
1527
+ }),
1528
+ {
1529
+ kind: "inline",
1530
+ value: serialiseStabilityPoolDatum({
1531
+ Account: {
1532
+ content: newAccountDatum
1533
+ }
1534
+ })
1535
+ },
1536
+ {
1537
+ lovelace: BigInt(
1538
+ params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1539
+ ),
1540
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1541
+ }
1542
+ ).addSignerKey(pkh.hash);
1543
+ }
1544
+ static async processRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid) {
1545
+ const redeemer = {
1546
+ ProcessRequest: {
1547
+ requestRef: {
1548
+ txHash: { hash: accountUtxo.txHash },
1549
+ outputIndex: BigInt(accountUtxo.outputIndex)
1550
+ }
1551
+ }
1552
+ };
1553
+ const stabilityPoolScriptRef = await scriptRef(
1554
+ params.scriptReferences.stabilityPoolValidatorRef,
1555
+ lucid
1556
+ );
1557
+ const accountDatum = parseAccountDatum(accountUtxo.datum);
1558
+ const stabilityPoolDatum = parseStabilityPoolDatum(stabilityPoolUtxo.datum);
1559
+ const tx = lucid.newTx().collectFrom(
1560
+ [stabilityPoolUtxo],
1561
+ serialiseStabilityPoolRedeemer(redeemer)
1562
+ ).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).readFrom([iAssetUtxo, govUtxo, stabilityPoolScriptRef]);
1563
+ if (!accountDatum.request) throw new Error("Account Request is null");
1564
+ if (accountDatum.request === "Create") {
1565
+ const accountTokenScriptRef = await scriptRef(
1566
+ params.scriptReferences.authTokenPolicies.accountTokenRef,
1567
+ lucid
1568
+ );
1569
+ tx.readFrom([accountTokenScriptRef]);
1570
+ const iassetUnit = params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset);
1571
+ const reqAmount = accountUtxo.assets[iassetUnit] ?? 0n;
1572
+ const newAccountSnapshot = {
1573
+ ...stabilityPoolDatum.snapshot,
1574
+ depositVal: {
1575
+ value: spAdd(accountDatum.snapshot.depositVal, mkSPInteger(reqAmount)).value
1576
+ }
1577
+ };
1578
+ const newDeposit = spAdd(
1579
+ stabilityPoolDatum.snapshot.depositVal,
1580
+ mkSPInteger(reqAmount)
1581
+ );
1582
+ const newSum = spAdd(
1583
+ stabilityPoolDatum.snapshot.sumVal,
1584
+ spDiv(
1585
+ spMul(
1586
+ mkSPInteger(
1587
+ BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces)
1588
+ ),
1589
+ stabilityPoolDatum.snapshot.productVal
1590
+ ),
1591
+ newDeposit
1592
+ )
1593
+ );
1594
+ const newStabilityPoolSnapshot = {
1595
+ ...stabilityPoolDatum.snapshot,
1596
+ depositVal: newDeposit,
1597
+ sumVal: newSum
1598
+ };
1599
+ const newEpochToScaleToSum = new Map(
1600
+ stabilityPoolDatum.epochToScaleToSum
1601
+ );
1602
+ newEpochToScaleToSum.set(
1603
+ {
1604
+ epoch: stabilityPoolDatum.snapshot.epoch,
1605
+ scale: stabilityPoolDatum.snapshot.scale
1606
+ },
1607
+ newSum
1608
+ );
1609
+ const stabilityPoolAssetToken = stabilityPoolUtxo.assets[iassetUnit] ?? 0n;
1610
+ const poolOutputValue = {
1611
+ lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
1612
+ [params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]: 1n,
1613
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: stabilityPoolAssetToken + reqAmount
1614
+ };
1615
+ tx.mintAssets(
1616
+ {
1617
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1618
+ },
1619
+ Data12.to(new Constr4(0, []))
1620
+ );
1621
+ tx.pay.ToContract(
1622
+ stabilityPoolUtxo.address,
1623
+ {
1624
+ kind: "inline",
1625
+ value: serialiseStabilityPoolDatum({
1626
+ StabilityPool: {
1627
+ content: {
1628
+ ...stabilityPoolDatum,
1629
+ snapshot: newStabilityPoolSnapshot,
1630
+ epochToScaleToSum: newEpochToScaleToSum
1631
+ }
1632
+ }
1633
+ })
1634
+ },
1635
+ poolOutputValue
1636
+ );
1637
+ tx.pay.ToContract(
1638
+ stabilityPoolUtxo.address,
1639
+ {
1640
+ kind: "inline",
1641
+ value: serialiseStabilityPoolDatum({
1642
+ Account: {
1643
+ content: {
1644
+ ...accountDatum,
1645
+ snapshot: newAccountSnapshot,
1646
+ request: null
1647
+ }
1648
+ }
1649
+ })
1650
+ },
1651
+ {
1652
+ lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
1653
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1654
+ }
1655
+ );
1656
+ } else if ("Adjust" in accountDatum.request) {
1657
+ const amount = accountDatum.request.Adjust.amount;
1658
+ const outputAddress = addressToBech32(
1659
+ lucid,
1660
+ accountDatum.request.Adjust.outputAddress
1661
+ );
1662
+ const myAddress = await lucid.wallet().address();
1663
+ const [updatedAccountSnapshot, reward, refInputs] = adjustmentHelper(
1664
+ stabilityPoolUtxo,
1665
+ newSnapshotUtxo,
1666
+ stabilityPoolDatum.snapshot,
1667
+ stabilityPoolDatum.epochToScaleToSum,
1668
+ accountDatum.snapshot
1669
+ );
1670
+ const govDatum = parseGovDatum(govUtxo.datum);
1671
+ const iassetDatum = parseIAssetDatum(iAssetUtxo.datum);
1672
+ const rewardLovelacesFee = calculateFeeFromPercentage2(
1673
+ govDatum.protocolParams.collateralFeePercentage,
1674
+ reward
1675
+ );
1676
+ const isDepositOrRewardWithdrawal = amount > 0n;
1677
+ const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
1678
+ const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, fromSPInteger(accountDatum.snapshot.depositVal));
1679
+ const newAccountSnapshot = {
1680
+ ...updatedAccountSnapshot,
1681
+ depositVal: spAdd(
1682
+ updatedAccountSnapshot.depositVal,
1683
+ mkSPInteger(balanceChange)
1684
+ )
1685
+ };
1686
+ const _newPoolDepositExcludingFee = spAdd(
1687
+ stabilityPoolDatum.snapshot.depositVal,
1688
+ mkSPInteger(balanceChange)
1689
+ );
1690
+ const newPoolDepositExcludingFee = _newPoolDepositExcludingFee.value > 0n ? _newPoolDepositExcludingFee : mkSPInteger(0n);
1691
+ const withdrawalFee = isDepositOrRewardWithdrawal || newPoolDepositExcludingFee.value === 0n ? 0n : calculateFeeFromPercentage2(
1692
+ iassetDatum.stabilityPoolWithdrawalFeePercentage,
1693
+ -balanceChange
1694
+ );
1695
+ const newPoolDeposit = spAdd(
1696
+ newPoolDepositExcludingFee,
1697
+ mkSPInteger(withdrawalFee)
1698
+ );
1699
+ const newPoolProduct = withdrawalFee === 0n ? stabilityPoolDatum.snapshot.productVal : spMul(
1700
+ stabilityPoolDatum.snapshot.productVal,
1701
+ spAdd(
1702
+ mkSPInteger(1n),
1703
+ spDiv(mkSPInteger(withdrawalFee), newPoolDepositExcludingFee)
1704
+ )
1705
+ );
1706
+ const newPoolSum = spAdd(
1707
+ stabilityPoolDatum.snapshot.sumVal,
1708
+ spDiv(
1709
+ spMul(
1710
+ mkSPInteger(
1711
+ BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces)
1712
+ ),
1713
+ newPoolProduct
1714
+ ),
1715
+ newPoolDeposit
1716
+ )
1717
+ );
1718
+ const newPoolSnapshot = {
1719
+ ...stabilityPoolDatum.snapshot,
1720
+ depositVal: newPoolDeposit,
1721
+ sumVal: newPoolSum,
1722
+ productVal: newPoolProduct
1723
+ };
1724
+ const newEpochToScaleToSum = setSumInEpochToScaleToSum(
1725
+ stabilityPoolDatum.epochToScaleToSum,
1726
+ stabilityPoolDatum.snapshot.epoch,
1727
+ stabilityPoolDatum.snapshot.scale,
1728
+ newPoolSum
1729
+ );
1730
+ await CollectorContract.feeTx(rewardLovelacesFee, lucid, params, tx);
1731
+ tx.readFrom([govUtxo, iAssetUtxo, ...refInputs]);
1732
+ tx.pay.ToContract(
1733
+ stabilityPoolUtxo.address,
1734
+ {
1735
+ kind: "inline",
1736
+ value: serialiseStabilityPoolDatum({
1737
+ StabilityPool: {
1738
+ content: {
1739
+ ...stabilityPoolDatum,
1740
+ snapshot: newPoolSnapshot,
1741
+ epochToScaleToSum: newEpochToScaleToSum
1742
+ }
1743
+ }
1744
+ })
1745
+ },
1746
+ {
1747
+ lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - reward,
1748
+ [params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + fromText6(
1749
+ params.stabilityPoolParams.stabilityPoolToken[1].unTokenName
1750
+ )]: 1n,
1751
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)] + balanceChange + withdrawalFee
1752
+ }
1753
+ );
1754
+ tx.pay.ToContract(
1755
+ stabilityPoolUtxo.address,
1756
+ {
1757
+ kind: "inline",
1758
+ value: serialiseStabilityPoolDatum({
1759
+ Account: {
1760
+ content: {
1761
+ ...accountDatum,
1762
+ snapshot: newAccountSnapshot,
1763
+ request: null
1764
+ }
1765
+ }
1766
+ })
1767
+ },
1768
+ {
1769
+ lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - 2000000n,
1770
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1771
+ }
1772
+ );
1773
+ if (myAddress !== outputAddress) {
1774
+ tx.pay.ToAddressWithData(
1775
+ outputAddress,
1776
+ {
1777
+ kind: "inline",
1778
+ value: Data12.to(
1779
+ {
1780
+ IndigoStabilityPoolAccountAdjustment: {
1781
+ spent_account: {
1782
+ txHash: { hash: accountUtxo.txHash },
1783
+ outputIndex: BigInt(accountUtxo.outputIndex)
1784
+ }
1785
+ }
1786
+ },
1787
+ ActionReturnDatum
1788
+ )
1789
+ },
1790
+ {
1791
+ lovelace: reward - rewardLovelacesFee + 2000000n,
1792
+ ...amount < 0n ? {
1793
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: -(amount - withdrawalFee)
1794
+ } : {}
1795
+ }
1796
+ );
1797
+ } else {
1798
+ }
1799
+ } else if ("Close" in accountDatum.request) {
1800
+ const outputAddress = addressToBech32(
1801
+ lucid,
1802
+ accountDatum.request.Close.outputAddress
1803
+ );
1804
+ const myAddress = await lucid.wallet().address();
1805
+ const [updatedAccountSnapshot, reward, refInputs] = adjustmentHelper(
1806
+ stabilityPoolUtxo,
1807
+ newSnapshotUtxo,
1808
+ stabilityPoolDatum.snapshot,
1809
+ stabilityPoolDatum.epochToScaleToSum,
1810
+ accountDatum.snapshot
1811
+ );
1812
+ const govDatum = parseGovDatum(govUtxo.datum);
1813
+ const iassetDatum = parseIAssetDatum(iAssetUtxo.datum);
1814
+ const rewardLovelacesFee = calculateFeeFromPercentage2(
1815
+ govDatum.protocolParams.collateralFeePercentage,
1816
+ reward
1817
+ );
1818
+ const fund = updatedAccountSnapshot.depositVal;
1819
+ const newPoolDepositExcludingFee = spSub(
1820
+ stabilityPoolDatum.snapshot.depositVal,
1821
+ fund
1822
+ );
1823
+ const withdrawnAmt = fund.value < 0n ? mkSPInteger(0n) : fund;
1824
+ const withdrawalFeeAmount = newPoolDepositExcludingFee.value === 0n ? 0n : calculateFeeFromPercentage2(
1825
+ iassetDatum.stabilityPoolWithdrawalFeePercentage,
1826
+ withdrawnAmt.value
1827
+ );
1828
+ const [newPoolDeposit, newPoolProduct] = updatePoolSnapshotWithdrawalFee(
1829
+ mkSPInteger(withdrawalFeeAmount),
1830
+ newPoolDepositExcludingFee,
1831
+ stabilityPoolDatum.snapshot
1832
+ );
1833
+ const newPoolSnapshot = {
1834
+ ...stabilityPoolDatum.snapshot,
1835
+ depositVal: newPoolDeposit,
1836
+ productVal: newPoolProduct
1837
+ };
1838
+ const accountTokenRef = await scriptRef(
1839
+ params.scriptReferences.authTokenPolicies.accountTokenRef,
1840
+ lucid
1841
+ );
1842
+ await CollectorContract.feeTx(rewardLovelacesFee, lucid, params, tx);
1843
+ tx.readFrom([govUtxo, iAssetUtxo, accountTokenRef, ...refInputs]);
1844
+ tx.mintAssets(
1845
+ {
1846
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: -1n
1847
+ },
1848
+ Data12.to(new Constr4(0, []))
1849
+ );
1850
+ const assetOutputAmountForSP = stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)] - fromSPInteger(withdrawnAmt) - withdrawalFeeAmount;
1851
+ tx.pay.ToContract(
1852
+ stabilityPoolUtxo.address,
1853
+ {
1854
+ kind: "inline",
1855
+ value: serialiseStabilityPoolDatum({
1856
+ StabilityPool: {
1857
+ content: {
1858
+ ...stabilityPoolDatum,
1859
+ snapshot: newPoolSnapshot
1860
+ }
1861
+ }
1862
+ })
1863
+ },
1864
+ {
1865
+ lovelace: stabilityPoolUtxo.assets.lovelace - reward,
1866
+ [params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + fromText6(
1867
+ params.stabilityPoolParams.stabilityPoolToken[1].unTokenName
1868
+ )]: 1n,
1869
+ ...assetOutputAmountForSP > 0n ? {
1870
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: assetOutputAmountForSP
1871
+ } : {}
1872
+ }
1873
+ );
1874
+ if (myAddress !== outputAddress) {
1875
+ tx.pay.ToAddressWithData(
1876
+ outputAddress,
1877
+ {
1878
+ kind: "inline",
1879
+ value: Data12.to(
1880
+ {
1881
+ IndigoStabilityPoolAccountClosure: {
1882
+ closed_account: {
1883
+ txHash: { hash: accountUtxo.txHash },
1884
+ outputIndex: BigInt(accountUtxo.outputIndex)
1885
+ }
1886
+ }
1887
+ },
1888
+ ActionReturnDatum
1889
+ )
1890
+ },
1891
+ {
1892
+ lovelace: accountUtxo.assets.lovelace + reward - rewardLovelacesFee,
1893
+ [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: fromSPInteger(withdrawnAmt) - withdrawalFeeAmount
1894
+ }
1895
+ );
1896
+ }
1897
+ }
1898
+ return tx;
1899
+ }
1900
+ };
1901
+
1902
+ // src/contracts/staking.ts
1903
+ import {
1904
+ applyParamsToScript as applyParamsToScript5,
1905
+ Constr as Constr5,
1906
+ Data as Data14,
1907
+ fromText as fromText8,
1908
+ validatorToAddress as validatorToAddress4,
1909
+ validatorToScriptHash as validatorToScriptHash5
1910
+ } from "@lucid-evolution/lucid";
1911
+
1912
+ // src/scripts/staking-validator.ts
1913
+ var _stakingValidator = {
1007
1914
  type: "PlutusV2",
1008
1915
  description: "Generated by Aiken",
1916
+ cborHex: "591ede591edb01000032323232323232322232323232323223232323232253330103232325333013300c30153754002264646464646464646464646464646464646464646464646464646464646464a64646466606a6064042264a66606c00426464646464a6660766070607a6ea80044c8c8c8c94ccc10cc1180084c8c8c94ccc118c1240084c94ccc10ccc0992411d496e76616c696420696e707574206265696e672076616c696461746564003375e605c608c6ea8020c0b8c118dd50028a99982199813249375472616e73616374696f6e206d757374206265207369676e6564206279206f776e6572206f66207374616b696e6720706f736974696f6e003302003200e15333043330264901204d757374206d696e742065786163746c792031207374616b696e67546f6b656e003375e6e98c090dd5981198231baa032374c60386054608c6ea810854ccc10ccc0992411f496e636f7272656374205374616b696e674d616e61676572206f7574707574003333301400a004301133048302d33048302d33048375066e00dd6981718231baa00d001304a3046375401a97ae04bd701bab302a304637546054608c6ea801530103d8798000133026490120496e636f7272656374205374616b696e67506f736974696f6e206f75747075740033333014330480024bd700021808998241808198241816998241ba900e330484c101a00033048302a3046375401a97ae04bd7025eb80cc05cc070c0a8c118dd502119809980a98231baa0420014c0103d87a800014a029405280a503302137566052608a6ea8004c050c114dd50208b182380099812998078038009198139bab302830443754002605060886ea8100c030cc11000d2f5c02c608800266604200a605060806ea80f1300103d87980003027303f37546046607e6ea8004c104c0f8dd50008b198118010139bac303f304030400023758607c00260746ea8098c0f0c0e4dd501a0a50375c607660706ea80b04c94ccc0d8c0bc08854ccc0d80084c8c8c8c94ccc0e8c0dcc0f0dd500089919192999820982200109919299981f9981124811f4d7573742061646a75737420706f736974696f6e206f7220756e7374616b6500325333040303400114a22a666080606a002294452818209baa0021330224910e4d697865642076657273696f6e73003375e60526608800a66088980103d87a80004bd70181518211baa3026304237540062940c0c4004cc020c0a0c100dd50008028b182100099980f8021811181f1baa03a4c0103d87980003025303d3754604a607a6ea8c084c0f4dd51820181e9baa00116330220020263756607c607e607e607e607e607e607e607e607e607e0046eb0c0f4004c0e4dd50128a5013253232333039302f02515333039005133232323232232323232533304330403045375400226464646464a666098609e00426464646464a66609a6606092011d496e76616c696420696e707574206265696e672076616c696461746564003375e607060a06ea8028c0e0c140dd50030a999826998182491643616e206e6f74206d696e7420616e7920746f6b656e000151533304d3303049010f4e6f20494e4459207374616b657273003371090001bad30383050375401e2a66609a660609212c436f6c6c6563746f7220696e70757473206d75737420757365207468652072696768742072656465656d65720033012005232323019002325333050304d00115333054305337540042930b0a99982818248008a99982a18299baa00214985854ccc140c11800454ccc150c14cdd50010a4c2c2c60a26ea8004cc064c0e4c144dd50009bab30543055305530553055305530553055305530553051375407a2a66609a6606092126436f6c6c6563746f72206f7574707574732063616e20636f6e7461696e206f6e6c7920414441003301200323375e606a60a26ea8004dd3180c180a1bab3035305137540022a66609a660609201404661696c20746f2072657475726e207468652073616d65206e756d626572206f66205554784f7320746f2074686520636f6c6c6563746f72206164647265737300533304d3370e602000a60200062660240064602e606a60a26ea8c0e4c144dd50008a501533304d330304913e4d6f7265207468616e20393525206f66207468652064697374726962757461626c652076616c75652068617320746f206265206469737472696275746564003371000466e0c011202813303049011f496e636f7272656374205374616b696e674d616e61676572206f7574707574003333301e00c301a330520094bd70180d99829181b99829181b99829182998281baa00f33052303733052375066e00dd6981c18281baa30343050375401e66e0ccdc1000a410181519534746eb4c0e0c140dd5007a5eb812f5c097ae04bd7019299982718258010800899999812800a45003232002323300100100222533305500114984c94ccc158004526132325333054305130563754660606eb8c158c168010dd7182b0010998028029982c8010008a9982aa49326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016305a002305800130580013305333760981014000375000497adef6c60222325333052302800114c103d87a80001303c33057374c00297ae03333302900148900005222325333055305200114c103d87a80001303f3305a375000297ae03370000200405a0546eacc0d0c140dd5181a18281baa0064c103d87a800014a029405280a5014a0294052819b810030013330120014800088cdc000098099bab3034305037540046603201260686609e00a97ae03330100014800088cdc000098089bab3032304e37546064609c6ea8008cc0b40208cdd7981a18261baa3034304c3754606060986ea800401058c134004ccc0a8018c0c4c124dd5022a6103d879800030123304a304b304c304c304c304c304c3048375408897ae0302f304737546056608e6ea8004c124c118dd50008b198158010179bac3047304830480023758608c00260846ea80b8c004004894ccc1080045200013370090011980100118228009119198008008019129998218008a5113253330403004304600213300300300114a0608c0024666046002910100488100222323300100100422533304200110041330033044001330020023045001303f303c375406e29404c8c8c8c94c8ccc0f8c0cc0a84c94ccc0fc0084c8c8c8c8c8c8c94ccc118c10cc120dd50008991919192999827182880109919299982818298010992999826982518279baa00113232533305330560021323232323253330543303749011d496e76616c696420696e707574206265696e672076616c696461746564003375e607e60ae6ea8038c0fcc15cdd50058a99982a1981ba490e4d697865642076657273696f6e73003375e607e60ae6ea8034c0fcc15cdd5181f982b9baa303b305737540122a6660a86606e921295374616b696e67206d616e61676572206973206e6f7420636f6e73756d656420636f72726563746c79003232301f00230480013301f303f305737540120202a6660a86606e920126546865207472616e73616374696f6e206973206e6f74207369676e6564206279206f776e65720033031043375c607e60ae6ea805454ccc150cc0dd240120457863656564206d6178696d756d207769746864726177616c20616d6f756e74003371200266e0001005854ccc150cc0dd24011f496e636f7272656374205374616b696e674d616e61676572206f7574707574003333302501130213305900d4bd7018111982c981f1982c981f1982c9ba8337006eb4c0fcc15cdd500300b182d982b9baa0064bd7025eb80cc0a0dd5981d982b9baa303b30573754012605200698103d879800015333054330374911643616e206e6f74206d696e7420616e7920746f6b656e0001c13303749120496e636f7272656374205374616b696e67506f736974696f6e206f7574707574003333302501130213305900d4bd7018111982c98109982c981f1982c981f982b9baa01533059374c004660b2607660ae6ea80192f5c097ae04bd70198141bab303b30573754607660ae6ea802ccc090c098c15cdd502980b26103d87a800014a029405280a5014a02940528191980080080111299982c8008a40002664464a6660b066e2000400840084004dd6982e982d1baa305a002305b00133002002305c001330173756607260aa6ea804cc058c154dd502099980b9811982a1baa0123038305437540060026605e6eacc0dcc14cdd5181b98299baa00a30223053375409e60940022c60a800260a06ea800458c04cc078c13cdd5181998279baa00116305100133302e0093035304d375409298103d879800016304f00133302c007302f304b375408e98103d87980003032304a3754605c60946ea8004c130c124dd50008b198170020191bab304a304b304b304b304b304b304b304b00237586092002609260920046eb0c11c004c10cdd5017982298211baa03d14a06eb4c110c104dd501a8a99981f18190150a99981f00089991911919191919192999823982218249baa001132323232533304f30520021323253330513054002132533304e304b3050375400226464a6660a860ae004264646464a6660a86606e9211d496e76616c696420696e707574206265696e672076616c696461746564003375e607e60ae6ea8034c0fcc15cdd50050a99982a1981ba490e4d697865642076657273696f6e73003375e607e60ae6ea8030c0fcc15cdd5181f982b9baa303b305737540102a6660a86606e921295374616b696e67206d616e61676572206973206e6f7420636f6e73756d656420636f72726563746c79003232301f00230480013301f303f3057375401001e2a6660a86606e920126546865207472616e73616374696f6e206973206e6f74207369676e6564206279206f776e65720033031043375c607e60ae6ea805054ccc150cc0dd24011b43616e206e6f7420756e7374616b65206c6f636b65642066756e64003051301500115333054330374901184d757374206275726e2031207374616b696e67546f6b656e003375e6e98c0d4dd5981a182b9baa043374c6052605a607660ae6ea814c4cc0dd24011f496e636f7272656374205374616b696e674d616e61676572206f7574707574003333302501030213305900c4bd7018111982c981f1982c981f1982c9ba8337026eb4c0fcc15cdd5002801982d982b9baa0054bd7025eb80cc0a0dd5981d982b9baa303b30573754010605200498103d879800014a029405280a5014a02940cc060dd5981d182b1baa013301730563754084666030604860aa6ea8048c0e4c154dd5001800998181bab303830543754607060a86ea8028c08cc150dd502818258008b182a80098289baa001163014301f30503754606860a06ea800458c148004ccc0bc024c0d8c138dd502526103d879800016305000133302d0073030304c375409098103d87980003033304b3754605e60966ea8004c134c128dd50008b198178020199bab304b304c304c304c304c304c304c304c00237586094002609460940046eb0c120004c110dd501818008009129998220008a4000266e012002330020023047001304430413754078294054ccc0f8cdc3a40140542a66607c002264646464a66608c60920042a6660846604a9201094d75737420766f7465003232533304430413046375400429445281929998221820800899192999825182680109924c64a66608e60880022a66609660946ea8008526161533304730400011533304b304a37540042930b0b18241baa00116304b001304737540042a666088607a002264646464a666098609e004264932999824182298251baa001132323232533305030530021324994ccc130c124c138dd5001899192999829182a8010a4c2c6eb8c14c004c13cdd50018b0b1bad30510013051002304f001304b37540022c2c609a002609a0046eb4c12c004c11cdd50010b18229baa0013300d302d3045375400200626604a9201124d757374206d696e74206e6f20746f6b656e0000a14a02c608e0026660486eb0c118008c118c11cc11cc11cc10cdd501fa6103d87980003756608a608c608c608c608c608c608c608c608c608c00260826ea80b45280999919191119191919192999824182298251baa00113253330493042304b37540022646464a6660a060a60042646464a66609e609860a26ea80044cc0c8cc03ccc150dd49b984901084d697373696e6720003305437526e60038cc150dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd70249003302d30103030009375c60aa60a46ea800454cc140cc03ccc150dd49b98491084d697373696e6720003305437526e60038cc150dd49b9849010d20757067726164652070617468004bd70249001632533304f304830513754002298103d87a8000130393305437526eb8c148c8cdd8182b000982b182b8009bac30553052375400297ae032330010013756606c60a46ea800c894ccc1500045300103d87a80001323253330523371e6eb8c1500080244c0f0cc15cdd39982b982a0011982b982a80125eb812f5c026600800800260b000460ac002a66609a6094609e6ea80044c8c8c8c94ccc154c1600084c9263304b001232375c60ac0046eb8c15000458dd5982b000982b0011bad3054001305037540022c6026603c609e6ea8c0ccc13cdd50008b1828800999817002804260103d8798000375c609e60986ea800458c0ccc12cdd5181998259baa302f304b3754609c60966ea800458cc0c0dd6182680201a1bab304c304d304d304d002375860960026096002608c6ea80c888dcc9919199800800802244100222533304a0021001132333004004304e00353330473044371a00426e600044cdc500119b8a00537300026e64dd718260011b98001300100122533304400114bd7009982298211823000998010011823800a49075374616b696e6700301e3041375407a606c607e6ea80ec8c10cc110c110c110c110c110c110c11000488c94ccc0f8c0dcc100dd500089919198008008029129998228008a5eb7bdb1804c8c94ccc10ccdc40029bad3049304a30463754608c004266090004660080080022660080080026092004608e0026eb4c110c104dd50008b181418201baa302830403754002444600e66e0ccdc119b81375a605060806ea8008dd6981418201baa0030014820302a32a68e894ccc0e8c0c0c0f0dd500089820181e9baa001153303b491134e6f7420616e20696e6c696e6520646174756d00163375e98101a000374c60326eacc060c0ecdd50139baf4c0103d87a8000233301148900488100001223253330383035303a37540022607c60766ea800454cc0e5240117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533303e00114c0103d87a80001323232533303d3375e00c607e0062604e6608400297ae0133005005002303f0023042002304000130043303c0024bd701818981b1baa032374a90011ba54801088cc060008c01800488ccc030dd7180e981a9baa002375c6032606a6ea800800488888c8cc004004cc068018c020014894ccc0e8004528099299981b99299981c19baf300a303b375400200e264a66607a002294454ccc0f4c1000044c8c8c94ccc0f0c078dd718210018a99981e180f0008a99981e181c981f1baa0091533303c337129000001099b89002482026fb808528099b89480000085280a50375c608260840046eb4c100c104c104004dd6181f8008a5032330010013300d3756604060786ea8008c03801c894ccc0f800452f5c0264666444646600200200644a66608800220062646608c6e9ccc118dd4803198231ba9375c60860026608c6ea0dd69822000a5eb80cc00c00cc120008c118004dd7181e8009bab303e001330030033042002304000114a0607a00429444cc00c00c004c0f40048c0d4c0d8c0d800494ccc0b8c0acc0c0dd5000899119baf301b30333754603660666ea8004008c0d0c0c4dd5000899119baf301b30333754002004606860626ea800488c8ccc00400400c0088894ccc0d400840044c8ccc010010c0e400cccccc024008dd7181a0009bab3035001222325333036300c00114c103d87a8000130203303b374c00297ae032333001001003002222533303c0021001132333004004304000333333011002375c60760026eb4c0f0004888c94ccc0f4c0e80045300103d87a80001302733042375000297ae03370000400202a607c00401c606e0044646600200200444a666064002297adef6c6013233034337606ea4dd718188009ba632330010013756606600444a66606a002297adef6c6013233037337606ea4dd7181a0009ba83370290001bad3035001330030033039002303700133003003303600230340012533302f00114a2294088888c8cc004004018894ccc0d00044cc0d4cdd81ba9006374c00a97adef6c601323232325333034300f3300700a002133039337606ea4028dd30048028a99981a19b8f00a002132533303530323037375400226607466ec0dd4805981d981c1baa001004100433300800a009001133039337606ea4008dd3000998030030019bab3036003375c60680046070004606c00244444646600200200c44a66606600226606866ec0dd48031ba80054bd6f7b630099191919299981998071980380500109981c19bb037520146ea002401454ccc0cccdc7805001099299981a1818981b1baa001133039337606ea402cc0e8c0dcdd5000802080219980400500480089981c19bb037520046ea0004cc01801800cdd6981a8019bae3033002303700230350012333002375c602660566ea8004dd7180798159baa001480088894ccc0a4c09800452f5bded8c0264646600200297adef6c60225333030001133031337606ea4018dd3001a5eb7bdb1804c8c8c8c94ccc0c0c02ccc0300280084cc0d4cdd81ba900a374c00e00a2a66606066e3c0280084cc0d4cdd81ba900a374c00e00626606a66ec0dd48011ba600133006006003375660640066eb8c0c0008c0d0008c0c8004c8cc0040052f5bded8c044a66605e00226606066ec0dd48021ba80034bd6f7b630099191919299981798051980580400109981a19bb037520106ea001c01454ccc0bccdc780400109981a19bb037520106ea001c00c4cc0d0cdd81ba900237500026600c00c0066eb4c0c400cdd71817801181980118188009baf4c0103d879800022533302633720004002298103d8798000153330263371e0040022980103d87a800014c103d87b80002233003375860566058605860586058605860586058605860506ea800800488c8cc00400400c894ccc0a8004528099299981399b8f375c605a00400829444cc00c00c004c0b400488ccc02c008dd7180718131baa001375c6014604c6ea80048c09cc0a0c0a0c0a0c0a00048c8cc004004008894ccc09800452f5bded8c0264646464a66604c6010004200626605666ec0dd48011ba600133006006003375660500066eb8c098008c0a8008c0a0004dc7a450022533301f33301f0014a094454cc08000840044004888c8cc0140108c008c020c090dd5000a99980f980e18109baa00112330063756600e60466ea800400c48cdc4240006660106eacc01cc08cdd50009bae300b302337540066eb8c01cc08cdd50019119198008008019129998118008a5eb804c8c94ccc084c0140084cc098008cc0100100044cc010010004c09c008c09400488c054ccc010008dd71803980f9baa001375c6006603e6ea80048c080c084004888c94ccc070c054c078dd50008a400026eb4c088c07cdd500099299980e180a980f1baa00114c0103d87a8000132330010013756604660406ea8008894ccc088004530103d87a8000132323253330213371e00e6eb8c08c00c4c02ccc098dd4000a5eb804cc014014008dd698118011813001181200099198008008021129998108008a6103d87a8000132323253330203371e00e6eb8c08800c4c028cc094dd3000a5eb804cc014014008dd598110011812801181180091191980080080191299980f8008a6103d87a800013232533301d3375e601060406ea80080144c01ccc0880092f5c0266008008002604600460420026e9520002301c001301637540166032602c6ea800458c060c064008c05c004c04cdd50008a4c26cac600200a464a66601e601800226464a66602a60300042930b1bae3016001301237540042a66601e60100022a66602660246ea8008526161533300f300500115333013301237540042930b0a999807980200089919299980a980c0010a4c2c6eb4c058004c048dd50010a99980798018008a99980998091baa00214985854ccc03ccdc3a40140022a66602660246ea8008526161533300f3370e90060008a99980998091baa00214985858c040dd50009b8748020dc3a400c6e1d2004325333009300600113232533300f3012002132498c01800458c040004c030dd50038a9998049801000899192999807980900109924ca6660166010601a6ea80044c8c8c8c8c8c94ccc054c0600084c8c926300e0023300b003232325333014301130163754002264646464a666038603e0042930b1bad301d001301d002375a6036002602e6ea800458c058008dd6980a0008b180b000980b0011bab30140013014002375c6024002601c6ea80045858c040004c030dd50038b18051baa006370e90011119198008008019129998070008a4c264660060066024004600660200024a66600c600660106ea80044c8c8c8c94ccc038c0440084c926300600116300f001300f002375a601a00260126ea80045894ccc014c008c01cdd500089919299980598070010a4c2c6eb4c030004c020dd50008b1b87480015cd2b9c5573aaae7955cfaba05742ae881"
1917
+ };
1918
+
1919
+ // src/types/indigo/staking.ts
1920
+ import { Data as Data13 } from "@lucid-evolution/lucid";
1921
+ import { match as match4, P as P4 } from "ts-pattern";
1922
+ var StakingParamsSchema = Data13.Object({
1923
+ stakingManagerNft: AssetClassSchema,
1924
+ stakingToken: AssetClassSchema,
1925
+ indyToken: AssetClassSchema,
1926
+ pollToken: AssetClassSchema,
1927
+ versionRecordToken: AssetClassSchema,
1928
+ collectorValHash: Data13.Bytes()
1929
+ });
1930
+ var StakingRedeemerSchema = Data13.Enum([
1931
+ Data13.Object({
1932
+ CreateStakingPosition: Data13.Object({
1933
+ creatorPkh: Data13.Bytes()
1934
+ })
1935
+ }),
1936
+ Data13.Literal("UpdateTotalStake"),
1937
+ Data13.Literal("Distribute"),
1938
+ Data13.Object({
1939
+ AdjustStakedAmount: Data13.Object({
1940
+ adjustAmount: Data13.Integer()
1941
+ })
1942
+ }),
1943
+ Data13.Literal("Unstake"),
1944
+ Data13.Literal("Lock"),
1945
+ Data13.Literal("UpgradeVersion")
1946
+ ]);
1947
+ var RewardSnapshotSchema = Data13.Object({ snapshotAda: Data13.Integer() });
1948
+ var StakingManagerContentSchema = Data13.Object({
1949
+ totalStake: Data13.Integer(),
1950
+ managerSnapshot: RewardSnapshotSchema
1951
+ });
1952
+ var StakingPositionContentSchema = Data13.Object({
1953
+ owner: Data13.Bytes(),
1954
+ lockedAmount: Data13.Map(
1955
+ Data13.Integer(),
1956
+ Data13.Tuple([Data13.Integer(), Data13.Integer()], {
1957
+ hasConstr: true
1958
+ })
1959
+ ),
1960
+ positionSnapshot: RewardSnapshotSchema
1961
+ });
1962
+ var StakingDatumSchema = Data13.Enum([
1963
+ Data13.Object({
1964
+ StakingManager: Data13.Object({ content: StakingManagerContentSchema })
1965
+ }),
1966
+ Data13.Object({
1967
+ StakingPosition: Data13.Object({ content: StakingPositionContentSchema })
1968
+ })
1969
+ ]);
1970
+ var StakingDatum = StakingDatumSchema;
1971
+ function parseStakingPositionDatum(datum) {
1972
+ return match4(Data13.from(datum, StakingDatum)).with({ StakingPosition: { content: P4.select() } }, (res) => res).otherwise(() => {
1973
+ throw new Error("Expected a StakingPosition datum.");
1974
+ });
1975
+ }
1976
+ function parseStakingManagerDatum(datum) {
1977
+ return match4(Data13.from(datum, StakingDatum)).with({ StakingManager: { content: P4.select() } }, (res) => res).otherwise(() => {
1978
+ throw new Error("Expected a StakingPosition datum.");
1979
+ });
1980
+ }
1981
+ function serialiseStakingDatum(d) {
1982
+ return Data13.to(d, StakingDatum);
1983
+ }
1984
+
1985
+ // src/helpers/staking-helpers.ts
1986
+ import { fromText as fromText7 } from "@lucid-evolution/lucid";
1987
+ var StakingHelpers = class {
1988
+ static async findStakingManagerByOutRef(stakingManagerRef, lucid) {
1989
+ return lucid.utxosByOutRef([stakingManagerRef]).then(
1990
+ (utxos) => utxos.map((utxo) => {
1991
+ if (!utxo.datum) return void 0;
1992
+ const datum = parseStakingManagerDatum(utxo.datum);
1993
+ return { utxo, datum };
1994
+ }).find((utxo) => utxo !== void 0)
1995
+ ).then((result) => {
1996
+ if (!result)
1997
+ throw new Error(
1998
+ "Unable to locate Staking Manager by output reference."
1999
+ );
2000
+ return result;
2001
+ });
2002
+ }
2003
+ static async findStakingManager(params, lucid) {
2004
+ return lucid.utxosAtWithUnit(
2005
+ StakingContract.address(params.stakingParams, lucid),
2006
+ params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText7(params.stakingParams.stakingManagerNFT[1].unTokenName)
2007
+ ).then(
2008
+ (utxos) => utxos.map((utxo) => {
2009
+ if (!utxo.datum) return void 0;
2010
+ const datum = parseStakingManagerDatum(utxo.datum);
2011
+ return { utxo, datum };
2012
+ }).find((utxo) => utxo !== void 0)
2013
+ ).then((result) => {
2014
+ if (!result)
2015
+ throw new Error(
2016
+ "Unable to locate Staking Manager by output reference."
2017
+ );
2018
+ return result;
2019
+ });
2020
+ }
2021
+ static async findStakingPositionByOutRef(stakingPositionRef, lucid) {
2022
+ return lucid.utxosByOutRef([stakingPositionRef]).then(
2023
+ (utxos) => utxos.map((utxo) => {
2024
+ if (!utxo.datum) return void 0;
2025
+ const datum = parseStakingPositionDatum(utxo.datum);
2026
+ return { utxo, datum };
2027
+ }).find((utxo) => utxo !== void 0)
2028
+ ).then((result) => {
2029
+ if (!result)
2030
+ throw new Error(
2031
+ "Unable to locate Staking Position by output reference."
2032
+ );
2033
+ return result;
2034
+ });
2035
+ }
2036
+ };
2037
+
2038
+ // src/contracts/staking.ts
2039
+ var StakingContract = class _StakingContract {
2040
+ static async openPosition(amount, params, lucid, stakingManagerRef) {
2041
+ const [pkh, _] = await addrDetails(lucid);
2042
+ const stakingManagerOut = stakingManagerRef ? await StakingHelpers.findStakingManagerByOutRef(
2043
+ stakingManagerRef,
2044
+ lucid
2045
+ ) : await StakingHelpers.findStakingManager(params, lucid);
2046
+ const stakingScriptRef = await _StakingContract.scriptRef(
2047
+ params.scriptReferences,
2048
+ lucid
2049
+ );
2050
+ const stakingTokenScriptRefUtxo = await _StakingContract.stakingTokenScriptRef(
2051
+ params.scriptReferences,
2052
+ lucid
2053
+ );
2054
+ const newStakingManagerDatum = {
2055
+ totalStake: stakingManagerOut.datum.totalStake + amount,
2056
+ managerSnapshot: {
2057
+ snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
2058
+ }
2059
+ };
2060
+ const stakingPositionDatum = {
2061
+ owner: pkh.hash,
2062
+ lockedAmount: /* @__PURE__ */ new Map([]),
2063
+ positionSnapshot: {
2064
+ snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
2065
+ }
2066
+ };
2067
+ const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText8(params.stakingParams.stakingToken[1].unTokenName);
2068
+ const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText8(params.stakingParams.indyToken[1].unTokenName);
2069
+ return lucid.newTx().collectFrom([stakingManagerOut.utxo], Data14.to(new Constr5(0, [pkh.hash]))).readFrom([stakingScriptRef]).pay.ToContract(
2070
+ stakingManagerOut.utxo.address,
2071
+ {
2072
+ kind: "inline",
2073
+ value: serialiseStakingDatum({
2074
+ StakingManager: { content: newStakingManagerDatum }
2075
+ })
2076
+ },
2077
+ stakingManagerOut.utxo.assets
2078
+ ).readFrom([stakingTokenScriptRefUtxo]).mintAssets(
2079
+ {
2080
+ [stakingToken]: 1n
2081
+ },
2082
+ Data14.void()
2083
+ ).pay.ToContract(
2084
+ _StakingContract.address(params.stakingParams, lucid),
2085
+ {
2086
+ kind: "inline",
2087
+ value: serialiseStakingDatum({
2088
+ StakingPosition: { content: stakingPositionDatum }
2089
+ })
2090
+ },
2091
+ {
2092
+ [stakingToken]: 1n,
2093
+ [indyToken]: amount
2094
+ }
2095
+ ).addSignerKey(pkh.hash);
2096
+ }
2097
+ static async adjustPosition(stakingPositionRef, amount, params, lucid, stakingManagerRef) {
2098
+ const [pkh, _] = await addrDetails(lucid);
2099
+ const now = Date.now();
2100
+ const stakingPositionOut = await StakingHelpers.findStakingPositionByOutRef(
2101
+ stakingPositionRef,
2102
+ lucid
2103
+ );
2104
+ const stakingManagerOut = stakingManagerRef ? await StakingHelpers.findStakingManagerByOutRef(
2105
+ stakingManagerRef,
2106
+ lucid
2107
+ ) : await StakingHelpers.findStakingManager(params, lucid);
2108
+ const stakingScriptRef = await _StakingContract.scriptRef(
2109
+ params.scriptReferences,
2110
+ lucid
2111
+ );
2112
+ const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText8(params.stakingParams.stakingToken[1].unTokenName);
2113
+ const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText8(params.stakingParams.stakingManagerNFT[1].unTokenName);
2114
+ const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText8(params.stakingParams.indyToken[1].unTokenName);
2115
+ const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
2116
+ const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
2117
+ const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
2118
+ const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
2119
+ const newLockedAmount = /* @__PURE__ */ new Map();
2120
+ for (const [key, value] of stakingPositionOut.datum.lockedAmount) {
2121
+ if (value[1] > now) {
2122
+ newLockedAmount.set(key, [value[0], value[1]]);
2123
+ }
2124
+ }
2125
+ return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).collectFrom([stakingPositionOut.utxo], Data14.to(new Constr5(3, [amount]))).collectFrom([stakingManagerOut.utxo], Data14.to(new Constr5(1, []))).pay.ToContract(
2126
+ stakingManagerOut.utxo.address,
2127
+ {
2128
+ kind: "inline",
2129
+ value: serialiseStakingDatum({
2130
+ StakingManager: {
2131
+ content: {
2132
+ ...stakingManagerOut.datum,
2133
+ totalStake: stakingManagerOut.datum.totalStake + amount
2134
+ }
2135
+ }
2136
+ })
2137
+ },
2138
+ {
2139
+ lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
2140
+ [stakingManagerToken]: 1n
2141
+ }
2142
+ ).pay.ToContract(
2143
+ stakingPositionOut.utxo.address,
2144
+ {
2145
+ kind: "inline",
2146
+ value: serialiseStakingDatum({
2147
+ StakingPosition: {
2148
+ content: {
2149
+ ...stakingPositionOut.datum,
2150
+ lockedAmount: newLockedAmount
2151
+ }
2152
+ }
2153
+ })
2154
+ },
2155
+ {
2156
+ [stakingToken]: 1n,
2157
+ [indyToken]: stakingPositionOut.utxo.assets[indyToken] + amount
2158
+ }
2159
+ ).addSignerKey(pkh.hash);
2160
+ }
2161
+ static async closePosition(stakingPositionRef, params, lucid, stakingManagerRef) {
2162
+ const [pkh, _] = await addrDetails(lucid);
2163
+ const stakingPositionOut = await StakingHelpers.findStakingPositionByOutRef(
2164
+ stakingPositionRef,
2165
+ lucid
2166
+ );
2167
+ const stakingManagerOut = stakingManagerRef ? await StakingHelpers.findStakingManagerByOutRef(
2168
+ stakingManagerRef,
2169
+ lucid
2170
+ ) : await StakingHelpers.findStakingManager(params, lucid);
2171
+ const stakingScriptRef = await _StakingContract.scriptRef(
2172
+ params.scriptReferences,
2173
+ lucid
2174
+ );
2175
+ const stakingTokenScriptRefUtxo = await _StakingContract.stakingTokenScriptRef(
2176
+ params.scriptReferences,
2177
+ lucid
2178
+ );
2179
+ const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText8(params.stakingParams.stakingToken[1].unTokenName);
2180
+ const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText8(params.stakingParams.stakingManagerNFT[1].unTokenName);
2181
+ const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText8(params.stakingParams.indyToken[1].unTokenName);
2182
+ const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
2183
+ const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
2184
+ const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
2185
+ const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
2186
+ return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).readFrom([stakingTokenScriptRefUtxo]).collectFrom([stakingPositionOut.utxo], Data14.to(new Constr5(4, []))).collectFrom([stakingManagerOut.utxo], Data14.to(new Constr5(1, []))).pay.ToContract(
2187
+ stakingManagerOut.utxo.address,
2188
+ {
2189
+ kind: "inline",
2190
+ value: serialiseStakingDatum({
2191
+ StakingManager: {
2192
+ content: {
2193
+ ...stakingManagerOut.datum,
2194
+ totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
2195
+ }
2196
+ }
2197
+ })
2198
+ },
2199
+ {
2200
+ lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
2201
+ [stakingManagerToken]: 1n
2202
+ }
2203
+ ).mintAssets(
2204
+ {
2205
+ [stakingToken]: -1n
2206
+ },
2207
+ Data14.void()
2208
+ ).addSignerKey(pkh.hash);
2209
+ }
2210
+ // Staking Validator
2211
+ static validator(params) {
2212
+ return {
2213
+ type: "PlutusV2",
2214
+ script: applyParamsToScript5(_stakingValidator.cborHex, [
2215
+ new Constr5(0, [
2216
+ new Constr5(0, [
2217
+ params.stakingManagerNFT[0].unCurrencySymbol,
2218
+ fromText8(params.stakingManagerNFT[1].unTokenName)
2219
+ ]),
2220
+ new Constr5(0, [
2221
+ params.stakingToken[0].unCurrencySymbol,
2222
+ fromText8(params.stakingToken[1].unTokenName)
2223
+ ]),
2224
+ new Constr5(0, [
2225
+ params.indyToken[0].unCurrencySymbol,
2226
+ fromText8(params.indyToken[1].unTokenName)
2227
+ ]),
2228
+ new Constr5(0, [
2229
+ params.pollToken[0].unCurrencySymbol,
2230
+ fromText8(params.pollToken[1].unTokenName)
2231
+ ]),
2232
+ new Constr5(0, [
2233
+ params.versionRecordToken[0].unCurrencySymbol,
2234
+ fromText8(params.versionRecordToken[1].unTokenName)
2235
+ ]),
2236
+ params.collectorValHash
2237
+ ])
2238
+ ])
2239
+ };
2240
+ }
2241
+ static validatorHash(params) {
2242
+ return validatorToScriptHash5(_StakingContract.validator(params));
2243
+ }
2244
+ static address(params, lucid) {
2245
+ const network = lucid.config().network;
2246
+ if (!network) {
2247
+ throw new Error("Network configuration is undefined");
2248
+ }
2249
+ return validatorToAddress4(network, _StakingContract.validator(params));
2250
+ }
2251
+ static async scriptRef(params, lucid) {
2252
+ return scriptRef(params.stakingValidatorRef, lucid);
2253
+ }
2254
+ static async stakingTokenScriptRef(params, lucid) {
2255
+ return scriptRef(params.authTokenPolicies.stakingTokenRef, lucid);
2256
+ }
2257
+ };
2258
+
2259
+ // src/contracts/interest-oracle.ts
2260
+ import {
2261
+ fromText as fromText9,
2262
+ toUnit as toUnit3,
2263
+ validatorToAddress as validatorToAddress5
2264
+ } from "@lucid-evolution/lucid";
2265
+
2266
+ // src/contracts/one-shot.ts
2267
+ import {
2268
+ addAssets as addAssets2,
2269
+ Constr as Constr6,
2270
+ Data as Data16,
2271
+ mintingPolicyToId,
2272
+ toUnit
2273
+ } from "@lucid-evolution/lucid";
2274
+
2275
+ // src/scripts/one-shot-policy.ts
2276
+ import {
2277
+ applyParamsToScript as applyParamsToScript6
2278
+ } from "@lucid-evolution/lucid";
2279
+
2280
+ // src/types/one-shot.ts
2281
+ import { Data as Data15 } from "@lucid-evolution/lucid";
2282
+ var OneShotParamsSchema = Data15.Object({
2283
+ referenceOutRef: Data15.Object({
2284
+ txHash: Data15.Bytes(),
2285
+ outputIdx: Data15.Integer()
2286
+ }),
2287
+ mintAmounts: Data15.Array(
2288
+ Data15.Object({
2289
+ /// Use hex encoded string
2290
+ tokenName: Data15.Bytes(),
2291
+ amount: Data15.Integer()
2292
+ })
2293
+ )
2294
+ });
2295
+ var OneShotParams = OneShotParamsSchema;
2296
+ function castOneShotParams(params) {
2297
+ return Data15.castTo(params, OneShotParams);
2298
+ }
2299
+
2300
+ // src/scripts/one-shot-policy.ts
2301
+ var oneShotPolicyData = {
2302
+ type: "PlutusV3",
2303
+ cborHex: "590426010100229800aba4aba2aba1aba0aab9faab9eaab9dab9a4888888896600264653001300800198041804800cdc3a400130080024888966002600460106ea800e33001375c601860126ea800eb300130023008375400915980098049baa0048a4d16402916401d374a90002444b30013005300b37546466446600400400244b30010018a60103d87a80008992cc004cdd7980998081baa0010048980299809000a5eb8226600600660280048070c0480050101bac3010300d375400a601e60186ea804e2b3001332259800800c52844ca600264b30013009300f37540031375a602060266eacc04cc040dd5000c5200040386024003375e6024602600337560049112cc0040062b3001300200589805801c52820208992cc004cdd79809000a610140008acc004cdc38021bad301330163756602600313003374c602e00514a0808a2b3001300c00489801803452820224044602a0028098653001001801c88cc04c008cc04cdd3000a5eb810011112cc00400a266002980103d87a80004bd6f7b63044ca60026eb8c0440066eacc048006602c0069112cc004cdc8a441000038acc004cdc7a4410000389980298051980b9ba60024bd70000c4cc015300103d87a8000006404d19800803c006446600e0046603266ec0dd48029ba6004001401c8098602800480922942294229410131bab300f3010301030103010300c37540086e98c8ca600200337586004601c6ea805697adef6c604004444b30010028800c66002007301400299914c004c0040066eb8c054c048dd50014dd6980318091baa002488966002601c00310068991919800800804112cc00400626603466ec0dd48079ba60034bd6f7b63044ca60026eb8c0600066eacc064006603a0049112cc004cdc8009801c4cc078cdd81ba9013374c00e00b15980099b8f0130038992cc004c058c070dd5000c4cc07ccdd81ba90143020301d37540020051002406c64b300159800800c528c528203c8a6103d87a8000898091980f9ba60014bd70203632330010010032259800800c4cc080cdd81ba900b375001497adef6c608994c004dd7180f000cdd6980f800cc08c0092225980099b9000f00389981219bb0375201e6ea00380162b30013371e01e00713259800980e18111baa00189981299bb03752020604c60466ea800400a20048108c966002603800314c103d87a80008980c198129ba80014bd7020423370000401d133024337606ea400cdd400119803003000a04040803021001407d13301e337606ea400cdd300119803003000a0344068301b0014064646400460080026602e66ec0dd48011ba80014bd6f7b63020261809801112cc00400629344c966002003149a264b3001337206eb8c04cc05c00cdd71809800c4cc010010cc058004c06000a2c8090c058005014180b000a026400c80888c040c04400629462c80522c805116401c300800130033754013149a26cac8009"
2304
+ };
2305
+ function mkOneShotPolicy(params) {
2306
+ return {
2307
+ type: oneShotPolicyData.type,
2308
+ script: applyParamsToScript6(oneShotPolicyData.cborHex, [
2309
+ castOneShotParams(params)
2310
+ ])
2311
+ };
2312
+ }
2313
+
2314
+ // src/contracts/one-shot.ts
2315
+ import { reduce } from "fp-ts/lib/Array";
2316
+ async function oneShotMintTx(lucid, params) {
2317
+ const oneShotPolicy = mkOneShotPolicy(params);
2318
+ const policyId = mintingPolicyToId(oneShotPolicy);
2319
+ const refUtxo = matchSingle(
2320
+ await lucid.utxosByOutRef([
2321
+ {
2322
+ txHash: params.referenceOutRef.txHash,
2323
+ outputIndex: Number(params.referenceOutRef.outputIdx)
2324
+ }
2325
+ ]),
2326
+ (_) => {
2327
+ throw new Error("Cannot find the reference UTXO for one-shot.");
2328
+ }
2329
+ );
2330
+ return [
2331
+ lucid.newTx().collectFrom([refUtxo]).mintAssets(
2332
+ reduce(
2333
+ {},
2334
+ (acc, entry) => addAssets2(acc, {
2335
+ [toUnit(policyId, entry.tokenName)]: entry.amount
2336
+ })
2337
+ )(params.mintAmounts),
2338
+ Data16.to(new Constr6(0, []))
2339
+ ).attach.MintingPolicy(oneShotPolicy),
2340
+ policyId
2341
+ ];
2342
+ }
2343
+ async function runOneShotMintTx(lucid, params) {
2344
+ const [tx, policyId] = await oneShotMintTx(lucid, params);
2345
+ const txHash = await tx.complete().then((tx2) => tx2.sign.withWallet().complete()).then((tx2) => tx2.submit());
2346
+ await lucid.awaitTx(txHash);
2347
+ return policyId;
2348
+ }
2349
+
2350
+ // src/scripts/interest-oracle-validator.ts
2351
+ import { applyParamsToScript as applyParamsToScript7 } from "@lucid-evolution/lucid";
2352
+ var interestOracleValidator = {
2353
+ type: "PlutusV2",
1009
2354
  cborHex: "590a3f590a3c0100003232323232323232223232322322533300932323253323300d3001300f375400426464646464a666024601e60286ea80044c8c8c8c94ccc058cc005241205458206973206e6f74207369676e6564206279206f7261636c65206f776e6572003232330010013758603c603e603e603e603e603e603e603e603e60366ea8038894ccc074004528099299980d19b8f375c604000400829444cc00c00c004c080004dd71801980c9baa01515332330173300249115496e636f72726563742074782076616c6964697479003232323232533301c32533301d300500114a22a66603a60220022944528180f1baa33003300d301f3754004601a603e6ea80044c94ccc074c0680045288a99980e98088008a5114a0603c6ea8cc00cc024c07cdd50011804980f9baa00114a06008601666040601666040600a660406ea0cdc09bad3008301e375402a6eb4c030c078dd500d25eb80cc080ccc06d28a60103d87a80004c0103d87980004bd70198101805998101802998101ba8337006eb4c020c078dd500a9bad300c301e375403497ae03302033301b4a298103d87a80004c0103d87980004bd7025eb80c00cc080c084c084c084c084c084c084c084c074dd50081119299980e180c8008a99980e180c980f1baa00214c103d87a800014c103d87980001533301c30040011533301c3004301e3754004298103d87a800014c103d87b800013232533301e3012001132533301f33710006002298103d87980001533301f337100020062980103d87b800014c103d87a8000375a604860426ea801054ccc078c06c004530103d87b800014c103d8798000301f37540066eb4c088c07cdd5001980e9baa002370e9002118041980e99299980c9806980d9baa001132533301a32533301f301e0011533301b300f301d00114a22a6660366030603a00229405858dd51803980e9baa300b301d3754006260086603e6ea00052f5c0260086603e6ea0cdc0000a400497ae0375a603e60386ea80044004c024c06cdd51804980d9baa0013301d325333019300d301b3754002264a66603464a66603e603c0022a666036601e603a002294454ccc06cc060c0740045280b0b1baa3007301d3754600e603a6ea800c4c010cc07cdd4000a5eb804c010cc07cdd419b80001480052f5c06eb4c07cc070dd500088009804980d9baa3005301b375400297ae01325333018330034912643757272656e742074696d652068617320746f206265203e3d206c6173745f736574746c656400337126eb4c004c06cdd500b1bad3005301b37540242a66466032660089212b496e74657265737420726174652068617320746f20626520696e2072616e6765205b30252c20313030255d0053330193001375a601460386ea8c028c070dd5009899b89375a601460386ea8c028c070dd500999b82480092080897a14a026600892120496e746572657374206f7261636c65206f757470757420696e636f72726563740033332222323300100132323300100101222533302500114bd7009919299981198028010998140011980200200089980200200098148011813800a99980f180d98101baa00413223375e602260466ea8c044c08cdd5000801181218109baa00413223375e602260466ea8004008c090c084dd50021129998118008a5013253330203253330213375e601460486ea80040184c94ccc0980045288a99981318148008991919299981299b8f375c605600691100153330253371e00291010015333025302230273754980103d87a800015333025300d00213371200490404df7010a501300d00214a02940dd7181518158011bad3029302a302a001375860500022940c8cc004004c8ccc004004dd5980818131baa003323300100100822533302900114bd6f7b6300991981599bb037526eb8c0a0004dd319198008009bab302a00222533302c00114bd6f7b6300991981719bb037526eb8c0ac004dd419b8148000dd69816000998018019818001181700099801801981680118158009112999814801080089919980200218168019991191980080080291299981700089981799bb037520086e9800d2f5bded8c0264646464a66605c66ebccc05402000930103d8798000133033337606ea4020dd30038028a99981719b8f008002132533302f302c3031375400226606866ec0dd4804981a98191baa001004100432533302f533303300114a229405300103d87a80001301f33034374c00297ae0323330010010080022225333035002100113233300400430390033322323300100100522533303a00113303b337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0e8cdd799810804001260103d879800013303f337606ea4020dd40038028a99981d19b8f008002132533303b3038303d375400226608066ec0dd48049820981f1baa001004100432533303b303800114c103d87a80001302b33040375000297ae03370000e00226607e66ec0dd48011ba800133006006003375a60780066eb8c0e8008c0f8008c0f0004dd7181a0009bad30350013037002133033337606ea4008dd3000998030030019bab3030003375c605c004606400460600026eb8c0a0004dd5981480098158011129998138008a5eb804c8ccc888c8cc00400400c894ccc0b4004400c4c8cc0bcdd3998179ba90063302f37526eb8c0b0004cc0bcdd41bad302d0014bd7019801801981880118178009bae30260013756604e00266006006605600460520022940c098008528899801801800981300091299980d99b9000200114c103d87980001533301b3371e0040022980103d87a800014c103d87b800030033301e30093301e0053301e4c0103d87a80004bd7025eb80cdd2a40086603c60126603c6ea0cdc01bad300a301c375402e64a66603466e20dd69801980e9baa01800113370666e0ccdc119b82337020026eb4c00cc074dd500c1bad300b301d3754600e603a6ea8061208080a0f6f4acdbe01b48202c227efa8052080897a153301b491254d75737420686f6c643a206e6f77203e206c61737420696e746572657374207570646174650016375a600c60386ea804ccc078c028c070dd50099980f1803180e1baa0134bd7025eb80dd59803180e1baa3006301c375400e6e25200014a029408c078c07cc07c004dd2a4004294052811299980b99980b800a504a22a6603000420022002600a602e6ea8c014c05cdd51800980b9baa0022301a301b0013018301537540022c6644646600200200644a666032002298103d87a80001323253330173375e601060346ea80080144c01ccc0700092f5c0266008008002603a00460360026eb0c05c010c05cc050dd50031ba5480008c058004dd6180a180a980a80098081baa003370e90010b18089809001180800098061baa00114984d9594ccc01cc010c024dd50008991919192999807980900109924c600e0062c6eb4c040004c040008c038004c028dd50008b2999802980118039baa0031323232323232533300f3012002132498c01c00c58dd698080009808001180700098070011bad300c001300837540062c4a66600a6004600e6ea80044c8c94ccc02cc03800852616375a601800260106ea800458dc3a4000ae695ce2ab9d5573caae7d5d02ba157441"
1010
2355
  };
2356
+ function mkInterestOracleValidator(params) {
2357
+ return {
2358
+ type: interestOracleValidator.type,
2359
+ script: applyParamsToScript7(interestOracleValidator.cborHex, [
2360
+ castInterestOracleParams(params)
2361
+ ])
2362
+ };
2363
+ }
2364
+
2365
+ // src/helpers/value-helpers.ts
2366
+ import { toUnit as toUnit2 } from "@lucid-evolution/lucid";
2367
+ function mkLovelacesOf(amount) {
2368
+ return { lovelace: amount };
2369
+ }
2370
+ function assetClassToUnit(ac) {
2371
+ return toUnit2(ac.currencySymbol, ac.tokenName);
2372
+ }
2373
+ function mkAssetsOf(assetClass, amount) {
2374
+ return {
2375
+ [assetClassToUnit(assetClass)]: amount
2376
+ };
2377
+ }
2378
+
2379
+ // tests/queries/interest-oracle-queries.ts
2380
+ async function findInterestOracle(lucid, interestNft) {
2381
+ const interestUtxo = await lucid.utxoByUnit(assetClassToUnit(interestNft));
2382
+ if (!interestUtxo.datum) throw new Error("No interest oracle utxo found");
2383
+ return [interestUtxo, parseInterestOracleDatum(interestUtxo.datum)];
2384
+ }
2385
+
2386
+ // src/contracts/interest-oracle.ts
2387
+ var InterestOracleContract = class {
2388
+ static async startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, withScriptRef = false, refOutRef, interestTokenName) {
2389
+ const tokenName = interestTokenName ?? "INTEREST_ORACLE";
2390
+ if (!refOutRef) {
2391
+ refOutRef = (await lucid.wallet().getUtxos())[0];
2392
+ }
2393
+ const [tx, policyId] = await oneShotMintTx(lucid, {
2394
+ referenceOutRef: {
2395
+ txHash: refOutRef.txHash,
2396
+ outputIdx: BigInt(refOutRef.outputIndex)
2397
+ },
2398
+ mintAmounts: [
2399
+ {
2400
+ tokenName: fromText9(tokenName),
2401
+ amount: 1n
2402
+ }
2403
+ ]
2404
+ });
2405
+ const validator = mkInterestOracleValidator(oracleParams);
2406
+ tx.pay.ToContract(
2407
+ validatorToAddress5(lucid.config().network, validator),
2408
+ {
2409
+ kind: "inline",
2410
+ value: serialiseInterestOracleDatum({
2411
+ unitaryInterest: initialUnitaryInterest,
2412
+ interestRate: {
2413
+ getOnChainInt: initialInterestRate
2414
+ },
2415
+ lastUpdated: initialLastInterestUpdate
2416
+ })
2417
+ },
2418
+ {
2419
+ lovelace: 2500000n,
2420
+ [toUnit3(policyId, fromText9(tokenName))]: 1n
2421
+ }
2422
+ );
2423
+ if (withScriptRef) {
2424
+ tx.pay.ToAddressWithData(
2425
+ validatorToAddress5(lucid.config().network, validator),
2426
+ void 0,
2427
+ void 0,
2428
+ validator
2429
+ );
2430
+ }
2431
+ return [
2432
+ tx,
2433
+ {
2434
+ currencySymbol: policyId,
2435
+ tokenName: fromText9(tokenName)
2436
+ }
2437
+ ];
2438
+ }
2439
+ static async feedInterestOracle(params, newInterestRate, lucid, assetClass, utxo, scriptRef2) {
2440
+ if (!assetClass && !utxo)
2441
+ throw new Error("Either interest oracle nft or utxo must be provided");
2442
+ if (assetClass && !utxo) {
2443
+ const [ioUtxo, _datum] = await findInterestOracle(lucid, assetClass);
2444
+ utxo = ioUtxo;
2445
+ }
2446
+ const now = BigInt(Date.now());
2447
+ const tx = lucid.newTx();
2448
+ const datum = parseInterestOracleDatum(utxo.datum);
2449
+ if (scriptRef2) {
2450
+ tx.readFrom([scriptRef2]);
2451
+ } else {
2452
+ tx.attach.Script(mkInterestOracleValidator(params));
2453
+ }
2454
+ tx.collectFrom(
2455
+ [utxo],
2456
+ serialiseFeedInterestOracleRedeemer({
2457
+ newInterestRate: {
2458
+ getOnChainInt: newInterestRate
2459
+ },
2460
+ currentTime: now
2461
+ })
2462
+ );
2463
+ tx.pay.ToContract(
2464
+ utxo.address,
2465
+ {
2466
+ kind: "inline",
2467
+ value: serialiseInterestOracleDatum({
2468
+ unitaryInterest: datum.unitaryInterest + calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
2469
+ interestRate: {
2470
+ getOnChainInt: newInterestRate
2471
+ },
2472
+ lastUpdated: now
2473
+ })
2474
+ },
2475
+ utxo.assets
2476
+ );
2477
+ tx.validFrom(Number(now) - ONE_SECOND);
2478
+ tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
2479
+ tx.addSignerKey(params.owner);
2480
+ return tx;
2481
+ }
2482
+ };
2483
+
2484
+ // src/scripts/cdp-creator-validator.ts
2485
+ import {
2486
+ applyParamsToScript as applyParamsToScript8
2487
+ } from "@lucid-evolution/lucid";
2488
+ var cdpCreatorValidator = {
2489
+ type: "PlutusV2",
2490
+ description: "",
2491
+ cborHex: "591a6c591a6901000032323232323232322232322323225333009323232533300c3006300e37540022646464646464646464646464646464646464a66603c603660406ea80644c8c8c8ccccc8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c88888c8c8c8c8c8c94ccc0f8c0ecc100dd50008991919192999821181e18221baa00213232533304433034490115496e636f72726563742074782076616c69646974790032325333046325333047302d00114a22a66608e6082002294452818241baa3301d303930493754004607260926ea80044c94ccc11cc1100045288a99982398208008a5114a060906ea8cc074c0c4c124dd5001181898249baa00114a06034606e66094606e660946036660946ea0cdc08071bad30163048375408897ae03304a3330454a298103d87a80004c0103d87980004bd7019825181b99825180d998251ba83370001c6eb4c058c120dd502225eb80cc128ccc11528a6103d87a80004c0103d87980004bd7025eb80c064c058c11cdd501d0a9998221981a24811754582069736e74207369676e6564206279206f776e657200330283758602a608e6ea80e804054ccc110cc0d124011543445043726561746f724e4654206d697373696e67003302e3756605e608e6ea8c0bcc11cdd5003181b98239baa04315333044330344912043445043726561746f72206f757470757420646f6573206e6f74206d617463680033333014008301a330490054bd70260107d87b9fd87980ff00301330373047375408698103d87a80001533304433034491174d696e7465642076616c756520697320696e76616c6964003375e6e98c0c8dd5981898239baa03a374c66660306026604e608e6ea810cdd7181798239baa043375c606e608e6ea800803c54ccc110cc0d1240115434450206f757470757420697320696e76616c69640033333014008303633049301a33049304a304b304b304b304b304b3047375408697ae04bd7019ba548010cc124c0d8cc124c0d8cc124c0d8cc124dd480825eb80cc124c0dcc11cdd5001198249ba800f33049303633049375001a660926ea0cdc01bad303730473754002a66608866e20dd6981398239baa00100d13370666e0ccdc119b823370201a6eb4c09cc11cdd50009bad303730473754605e608e6ea8005208080a0f6f4acdbe01b48202c227efa8052080897a15330454901254d75737420686f6c643a206e6f77203e206c61737420696e7465726573742075706461746500164bd7025eb812f5c097ae033012301330273047375408601c980103d87980001325332330463303649115556e646572636f6c6c61746572697a65642043445000337126eb4c0e4c124dd51980c9980c981998249baa00430383304b3750600202297ae03039304937540046eb4c0e4c124dd51980c981c198259ba830010104bd70181c198259ba833704906400a410112f497ae01533304633036491164e6f6e706f736974697665206d696e74656420616d7400302e011153330463303649012e4d7573742070726f76696465206d6f7265207468616e206d696e436f6c6c61746572616c496e4c6f76656c61636500337126eb4c060c124dd50228080a9998231981b249174f7261636c652063616e2774206265206578706972656400333046325333047304130493754002266e24dd6981918251baa003375a609a60946ea800454cc121240124496e636f7272656374207472616e73616374696f6e2076616c69646974792072616e67650016303930493754606260926ea8c060c124dd501e2504a226606c9201194d757374207061792064656274206d696e74696e67206665650033322232533304a3032002132533304b3232302c00232533304d304a00115333051305037540042930b0a99982698238008a99982898281baa00214985854ccc134c0cc00454ccc144c140dd50010a4c2c2c609c6ea8004c94ccc130c124c138dd50008982918279baa001153304d49117436f756c64206e6f742066696e642072656465656d6572001632323300100100722533305200114c0103d87a8000132323253330513375e00c60a600626086660ac00297ae0133005005002305300230560023054001302133050303e304e375400297ae013333301b00f302133050303d33050002330504c103d87a80004bd7025eb8130107d87b9fd87980ff00330193756606c609c6ea8c0d8c138dd5000801a60103d879800014a064a66609e0022a66098921284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400161533304f305200113051001153304c4901284d757374207370656e64203120696e7075742066726f6d20636f6c6c6563746f722073637269707400163303301123375e607c609c6ea8c0f8c138dd5181b18271baa00100214a2603e6609c6ea40092f5c06eacc130c134c134c134c134c134c134c134c134c134c124dd501e1bae30133049375408a6644a66609066e2400520001480004dd6981d98259baa303a3304d375066e0cc00cdd6981d98259baa3301b303a3304d375000297ae0002375a607660966ea8c0e8cc134dd419b8248320052080897a4bd7025eb80c04cc124dd50021bad303930493754660326070660966ea00452f5c0607260926ea80085280a5014a06e092080897a14a064a66608a6084608e6ea800454cc11924012543616e6e6f74206f70656e206120434450206f6620612064656c69737465642061737365740016132320025333046304330483754002264646464a66609c60a20042649318118018b1bad304f001304f002304d001304937540022c6054605060906ea8c0c0c120dd51929998250008a99823a492145787065637465642065786163746c79206f6e65206f7261636c6520696e70757400161533304a304d0011304c001153304749012145787065637465642065786163746c79206f6e65206f7261636c6520696e707574001633302c00a304b30483754609660906ea8005300103d8798000302f3047375400429405280a5014a0294052819190012999822182098231baa0011323232323232533304e3051002132498c08c00c58dd698278009827801182680098268011bad304b001304737540022c6050604c608c6ea8c0b8c118dd51929998240008a99822a492a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e707574001615333048304b0011304a001153304549012a45787065637465642065786163746c79206f6e6520696e746572657374206f7261636c6520696e707574001633302a008302630463754002980103d87980003048304537540042c64a666084607e00226464a6660906096004264932999822182098231baa001132323232323232325333050305300213232498c94ccc138c12c0044c8c8c8c94ccc158c16400852616375a60ae00260ae0046eb4c154004c144dd50018a9998271824000899191919299982b182c8010a4c2c6eb4c15c004c15c008dd6982a80098289baa00316304f3754004604800e2c60a200260a20046eb4c13c004c13c008dd718268009826801182580098239baa00116163049001304537540042a666084607800226464a6660906096004264932999822182098231baa001132323232323232323232323232323232323232323232323232323232533306430670021323232323232323232323232498c10c030c10c03cc108040c104044c100048c0fc04cc0f8050c0f4054c0f0058c0ec05cc0f4060c94ccc184c1780044c8c94ccc19cc1a80084c926303c001163068001306437540342a6660c260b600226464a6660ce60d4004264932999831983018329baa001132325333069306c002132498c10400458c1a8004c198dd50008b0b183400098321baa01a16306237540322c60ca00260ca00464a6660c460c20022a6660bc60b060c0002294454ccc178c16cc1800045280b0b1baa3063001306300230610013061002305f001305f002305d001305d002305b001305b0023059001305900230570013057002305500130550023053001305300230510013051002304f001304f002304d001304d002375c6096002608e6ea80045858c124004c114dd50010b18219baa0013025302330433754605660866ea8c94ccc11400454cc10924012145787065637465642065786163746c79206f6e652069617373657420696e707574001615333045304800113047001153304249012145787065637465642065786163746c79206f6e652069617373657420696e707574001633302700530463047304730473043375407e980103d8798000303230423754605460846ea8004c110c104dd50008b198170020189bac304230430023758608200260820046eb0c0fc004c0ecdd50171181d181d981d981d981d981d981d800911999804001244100488100001233225333034302e4800052f5bded8c0264646600200297adef6c6022533303b00113303c337606ea4014dd3001a5eb7bdb1804c8c8c8c94ccc0ecc068cc0540240084cc100cdd81ba9009374c00e00a2a66607666e3c0240084cc100cdd81ba9009374c00e00626608066ec0dd48011ba6001330060060033756607a0066eb8c0ec008c0fc008c0f4004c8cc0040052f5bded8c044a66607400226607666ec0dd4801a610101004bd6f7b630099191919299981d180c9980a00380109981f99bb0375200e9810101000051533303a3371e00e00426607e66ec0dd4803a6101010000313303f337606ea4008dd4000998030030019bad303c003375c6074004607c00460780026eb8c094c0d4dd50009bae301d303537540024444464660020026603e00ca66606c606660706ea80144c88cdd79815981d9baa302b303b3754002004607860726ea80144c88cdd79815981d9baa001002303c3039375400a44a66607600229404c94ccc0e0c94ccc0e4cdd7980e181e1baa001007132533303e00114a22a66607c60820022646464a66607a60586eb8c10c00c54ccc0f4c0b000454ccc0f4c0e8c0fcdd50048a99981e99b89480000084cdc48012410137dc0429404cdc4a400000429405281bae30423043002375a6082608460840026eb0c1000045281919800800991998008009bab3026303e3754006646600200201244a666082002297adef6c6013233043337606ea4dd718200009ba632330010013756608400444a666088002297adef6c6013233046337606ea4dd718218009ba83370290001bad3044001330030033048002304600133003003304500230430012225333041002100113233300400430450033333301b002375c60800026eacc104004888c94ccc108c0740045300103d87a80001303433047374c00297ae03233300100100300222253330480021001132333004004304c00333333023002375c608e0026eb4c120004888c94ccc124c1180045300103d87a80001303b3304e375000297ae03370000400203e6094004030608600444a66607e002297ae01323332223233001001003225333045001100313233047374e6608e6ea4018cc11cdd49bae30440013304737506eb4c1140052f5c0660060066092004608e0026eb8c0f8004dd5981f80099801801982180118208008a50303e00214a2266006006002607c0024606c606e606e606e606e606e606e606e606e0024606a606c606c606c606c606c606c606c002446042660686ea0cdc199b82375a604460646ea8008dd6981118191baa0014820225e92f5c04444a666060605a002200826666601a0080066464004646600200200444a66606e002293099299981c0008a4c26464a66606c606660706ea8cc040dd7181c181e0021bae30380021330050053303b0020011533037491326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016303c002303a001303a00133035337606ea4008dd4000a5eb7bdb180888c94ccc0d0c03c004530103d87a80001302633039374c00297ae033333011001005004222325333037303400114c103d87a8000130293303c375000297ae03370000200401a0144603c6606264a66605a604e605e6ea80044c94ccc0b8c94ccc0ccc0c800454ccc0bcc0a4c0c40045288a999817981618188008a5016163754603260626ea8c084c0c4dd500189802198199ba80014bd7009802198199ba833700002900125eb80dd6981998181baa0011001301f302f3754603e605e6ea8004cc0c4c94ccc0b4c09cc0bcdd5000899299981719299981998190008a999817981498188008a511533302f302c303100114a02c2c6ea8c064c0c4dd5180c98189baa0031300433033375000297ae01300433033375066e0000520014bd701bad3033303037540022002603e605e6ea8c05cc0bcdd5000a5eb80dd2a40044464a66605860520022a6660586052605c6ea8008530103d87a800014c103d87980001533302c30120011533302c3012302e3754004298103d87a800014c103d87b800013232533302e3028001132533302f33710006002298103d87980001533302f337100020062980103d87b800014c103d87a8000375a606860626ea801054ccc0b8c0ac004530103d87b800014c103d8798000302f37540066eb4c0c8c0bcdd500198169baa002232533302a30270011323253330303033002149858dd7181880098169baa0021533302a30240011533302e302d37540042930b0b18159baa001253330283025302a375400226464a66605c60620042930b1bad302f001302b37540022c44a66605066e40008004530103d8798000153330283371e0040022980103d87a800014c103d87b80002533302a00114a2294094ccc094c088c09cdd5000899191919299981698180010a4c2c6eb8c0b8004c0b8008dd7181600098141baa0011622222323300100100622533302e00113302f337606ea4018dd3002a5eb7bdb1804c8c8c8c94ccc0b8c034cc01c0280084cc0cccdd81ba900a374c01200a2a66605c66e3c0280084c94ccc0bcc0b0c0c4dd500089981a19bb03752016606a60646ea80040104010ccc0200280240044cc0cccdd81ba9002374c0026600c00c0066eacc0c000cdd718170011819001181800091111191980080080311299981680089981719bb0375200c6ea00152f5bded8c0264646464a66605a60186600e01400426606466ec0dd48051ba80090051533302d3371e014004264a66605c605660606ea80044cc0cccdd81ba900b303430313754002008200866601001401200226606466ec0dd48011ba800133006006003375a605e0066eb8c0b4008c0c4008c0bc004dd7a6103d8798000375c604e0066eb4c09c008dd698138009bad302730280013027001302600130213754032266646464446464646464a666050604a60546ea80044c94ccc0a4c08cc0acdd500089919192999818181980109919192999817981618189baa00113301f3300f3303437526e61241084d697373696e6720003303437526e60038cc0d0dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd7024900330133010301d009375c606a60646ea800454cc0c0cc03ccc0d0dd49b98491084d697373696e6720003303437526e60038cc0d0dd49b9849010d20757067726164652070617468004bd70249001632533302f302930313754002298103d87a8000130213303437526eb8c0c8c8cdd8181b000981b181b8009bac30353032375400297ae032330010013756603460646ea800c894ccc0d00045300103d87a80001323253330323371e6eb8c0d00080244c090cc0dcdd39981b981a0011981b981a80125eb812f5c02660080080026070004606c002a66605a6054605e6ea80044c8c8c8c94ccc0d4c0e00084c926323300100100222533303700114984c8cc00c00cc0ec008c8c8dd7181c0011bae30360013039001163756606c002606c0046eb4c0d0004c0c0dd50008b1808980798179baa3017302f37540022c606200266602200a01098103d8798000375c605e60586ea800458c06cc0acdd5180d98159baa3013302b3754605c60566ea800458cc060dd6181680200d9bab302c302d302d302d002375860560026056002604c6ea806488dcc9919199800800802244100222533302a0021001132333004004302e00353330273024371a00426e600044cdc500119b8a00537300026e64dd718160011b98001300100122533302400114bd7009981298111813000998010011813800a490a43445043726561746f7200300b3021375403a46048604a604a00244646600200200644a66604800229404c94ccc084cdc79bae302700200414a2266006006002604e0024a6660386004603c6ea80044c088c07cdd50008a9980ea481134e6f7420616e20696e6c696e6520646174756d0016370e9002111191980300211801180498109baa001533301c3019301e3754002246600e6eacc020c080dd50008018918029998049bab3008302037540026eb8c040c080dd50019bae3008302037540066e21200022323300100100322533301f00114bd7009919299980e980280109981100119802002000899802002000981180118108009118091998020011bae300b301b37540026eb8c00cc06cdd50009180e180e80091119299980c1809180d1baa0011480004dd6980f180d9baa0013253330183012301a37540022980103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a80001323232533301d3371e00e6eb8c07c00c4c03ccc088dd4000a5eb804cc014014008dd6980f80118110011810000991980080080211299980e8008a6103d87a80001323232533301c3371e00e6eb8c07800c4c038cc084dd3000a5eb804cc014014008dd5980f0011810801180f8009180d180d980d980d980d8009191980080080111299980c8008a5eb7bdb1804c8c8c8c94ccc064c020008400c4cc078cdd81ba9002374c0026600c00c0066eacc06c00cdd7180c801180e801180d8009b8f4881002253330123330120014a094454cc04c0084004400488c8cc00400400c894ccc05c0045300103d87a80001323253330153375e601060306ea80080144c01ccc0680092f5c0266008008002603600460320026e952000230140013012300f37540022c60226024004602000260186ea80045261365632533300830050011323232323232323253330143017002149858dd6980a800980a8011bad30130013013002375a602200260220046eb8c03c004c02cdd50018a99980418010008a99980618059baa00314985858c024dd50011b8748008c94ccc014c008c01c00454ccc024c020004526161637540046e1d20005734ae7155ceaab9e5573eae815d0aba21"
2492
+ };
2493
+ var mkCDPCreatorValidator = (params) => {
2494
+ return {
2495
+ type: cdpCreatorValidator.type,
2496
+ script: applyParamsToScript8(cdpCreatorValidator.cborHex, [
2497
+ castCDPCreatorParams(params)
2498
+ ])
2499
+ };
2500
+ };
2501
+ var mkCDPCreatorValidatorFromSP = (params) => {
2502
+ return {
2503
+ type: cdpCreatorValidator.type,
2504
+ script: applyParamsToScript8(cdpCreatorValidator.cborHex, [
2505
+ castCDPCreatorParams({
2506
+ cdpCreatorNft: fromSystemParamsAsset(params.cdpCreatorNft),
2507
+ cdpAssetCs: params.cdpAssetCs.unCurrencySymbol,
2508
+ cdpAuthTk: fromSystemParamsAsset(params.cdpAuthTk),
2509
+ iAssetAuthTk: fromSystemParamsAsset(params.iAssetAuthTk),
2510
+ versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
2511
+ cdpScriptHash: params.cdpScriptHash,
2512
+ collectorValHash: params.collectorValHash,
2513
+ minCollateralInLovelace: BigInt(params.minCollateralInLovelace),
2514
+ biasTime: BigInt(params.biasTime)
2515
+ })
2516
+ ])
2517
+ };
2518
+ };
2519
+
2520
+ // src/scripts/poll-shard-validator.ts
2521
+ import {
2522
+ applyParamsToScript as applyParamsToScript9
2523
+ } from "@lucid-evolution/lucid";
2524
+
2525
+ // src/types/indigo/poll-shard.ts
2526
+ import { Data as Data17 } from "@lucid-evolution/lucid";
2527
+ var PollShardParamsSchema = Data17.Object({
2528
+ pollToken: AssetClassSchema,
2529
+ stakingToken: AssetClassSchema,
2530
+ indyAsset: AssetClassSchema,
2531
+ stakingValHash: Data17.Bytes()
2532
+ });
2533
+ var PollShardParams = PollShardParamsSchema;
2534
+ function castPollShardParams(params) {
2535
+ return Data17.castTo(params, PollShardParams);
2536
+ }
2537
+
2538
+ // src/scripts/poll-shard-validator.ts
2539
+ var pollShardValidatorData = {
2540
+ type: "PlutusV2",
2541
+ description: "Generated by Aiken",
2542
+ cborHex: "59166859166501000032323232323232322232323232322322533300b323232533300e300830103754002264a66601e601260226ea80344c8c8c8c8c8c8c8c8c8c94c8ccc068c054c070dd50090999191919191919191911919299981518168010991919299981698180010992999815181218161baa00113232533303030330021323232533302f3301f4911d496e76616c696420696e707574206265696e672076616c696461746564003375e042602e60646ea802854ccc0bccc07d2401225468652070726f706f73616c206578636565647320766f74696e6720706572696f64003322325333032302c30343754002264a66606664a666070606e0022a666068605c606c002294454ccc0d0c0bcc0d80045280b0b1baa301c303637546038606c6ea80104cdc4000801899b89001003375a6070606a6ea8004528180c981a1baa301a30343754004602060646ea808cdd6980898191baa0201533302f3301f49011c54686520706f6c6c206f757470757420697320696e636f7272656374003333300e3758602260646ea808cc074cc0d00252f5c0602c66068603a6606864603e6606a606c0026606a64a666062605860666ea80384c080cc0d8dd419b80375a603260686ea800400cc0e0c0d0dd5000898101981b181b981a1baa00133036375066e00dd6980d181a1baa0010034bd70180c98199baa021303730370013032375404097ae04bd701bab301830323754603060646ea8029300103d87980001533302f3301f4910e4d697865642076657273696f6e73003375e602e60646ea8c05cc0c8dd5180c18191baa007301d33034301a3032375405c97ae01533302f3301f49127546865207472616e73616374696f6e206d757374206265207369676e6564206279206f776e6572003232330010013758606e6070607060706070607060706070607060686ea8094894ccc0d8004528099299981999b8f375c607200400829444cc00c00c004c0e4004dd7180b98191baa0041533302f3301f4911a5573657220766f74656420666f7220706f6c6c206265666f72650033302f3300d002375a602e60646ea8081282511533302f3301f491124d757374206d696e74206e6f20746f6b656e003375e6e98c8cc004004dd5981b181b981b981b981b98199baa02422533303500114bd6f7b630099191919299981a980a801080189981d19bb037520046e98004cc01801800cdd5981b8019bae3035002303900230370014c0101a0001533302f3301f491245374616b696e67506f736974696f6e206d757374207570646174652070726f7065726c79003333300e3758602260646ea808cc074cc0d0c078cc0d0c074cc0d0c068c0c8dd501725eb80cc0d130103d87a80004bd7025eb80c058cc0d0c074cc0d0c8c07ccc0d4c0d8004cc0d4dd319912999819198080028010991980080080311299981c0008a5eb7bdb1804cc0e4c8c94ccc0d8cdc3800803099bb0375000200a20046eb4c0dc004c0e8004cc008008c0ec0044c8c8cc00400401c894ccc0e4004400c4cc0e8c0ec004cc008008c0f0004cc0dccdd81ba80020014bd6f7b6301bad301830333754042603e6606a6ea0008cc0d4c048c0ccdd5010a5eb80c0dcc0dc004c0c8dd500225eb812f5c06eacc060c0c8dd5180c18191baa0074c0103d87a800013301f4901275374616b696e6720506f736974696f6e206d75737420757365204c6f636b2072656465656d65720032323375e004980103d87e8000325333031302c001132325333037303a002149858dd7181c000981a1baa00215333031302b00115333035303437540042930b0a99981898168008a99981a981a1baa00214985854ccc0c4cdc3a400c00226464a66606e60740042930b1bad3038001303437540042a66606266e1d200800115333035303437540042930b0a99981899b874802800454ccc0d4c0d0dd50010a4c2c2a66606266e1d200c00115333035303437540042930b0b18191baa0013301c30173032375400e6eacc06cc0c8dd50118a5014a029405280a5014a02940528199119980a8011bae3018303337540026eb8c064c0ccdd50009bab301730313754602e60626ea8018c040c0c4dd501699192999817981498189baa001132323300100100422533303600114bd6f7b63009919299981a19b88005375a60746076606e6ea8c0dc0084cc0e4008cc0100100044cc010010004c0e8008c0e0004dd6981a98191baa00116301630313754602c60626ea8c03cc0c4dd50111bab301630303754004a666058604e605c6ea80044c8c8c8c8c8c94ccc0d8c0e40084c8c9265333033302e3035375400426464a66607260780042930b1bad303a001303637540042c6605e00646464a66606a6060606e6ea80044c8c8c8c94ccc0f4c10000852616375a607c002607c0046eb4c0f0004c0e0dd50008b181b8011bad303500116303700130370023756606a002606a0046eb8c0cc004c0bcdd50008b0b181880098169baa0011632533302a3026302c375400226060605a6ea800454cc0ad241134e6f7420616e20696e6c696e6520646174756d0016300b302c3754602460586ea800458c0b8004ccc028dd6180798151baa01b3010302a375404c98103d8798000300e30293754601e60526ea800458c0ac004ccc01cdd6180618139baa018300c3027375404698103d8798000225333024301f30263754646600200200644a666054002298103d87a80001323253330283370e6eb4c0a80080144c05ccc0b4dd399816981500119816981580125eb812f5c0266008008002605c00460580022944528111111980819805002a999813181098141baa00413223375e602060566ea8c040c0acdd5000801181618149baa00413223375e602060566ea8004008c0b0c0a4dd50021299981399baf3009302a3754002008264a666058002294454ccc0b0c0bc0044c8c8c94ccc0acc02cdd718188018a99981598058008a999815981318169baa0061533302b337129000001099b89002482026fb808528099b89480000085280a50375c606060620046eb4c0bcc0c0c0c0004dd618170008a503233001001323330010013756602460586ea800cc8cc004004018894ccc0bc00452f5bded8c02646606266ec0dd49bae302e001374c64660020026eacc0c0008894ccc0c800452f5bded8c02646606866ec0dd49bae3031001375066e052000375a606400266006006606c00460680026600600660660046062002444a66605e004200226466600800860660066644646600200200a44a66606800226606a66ec0dd48021ba60034bd6f7b630099191919299981a19baf3301a0080024c0103d8798000133039337606ea4020dd30038028a99981a19b8f008002132533303530303037375400226607466ec0dd4804981d981c1baa0010041004325333035533303900114a229405300103d87a8000130243303a374c00297ae032333001001008002222533303b0021001132333004004303f00333223233001001005225333040001133041337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc100cdd799813004001260103d8798000133045337606ea4020dd40038028a99982019b8f0080021325333041303c3043375400226608c66ec0dd4804982398221baa0010041004325333041303c00114c103d87a80001303033046375000297ae03370000e00226608a66ec0dd48011ba800133006006003375a60840066eb8c100008c110008c108004dd7181d0009bad303b001303d002133039337606ea4008dd3000998030030019bab3036003375c60680046070004606c0026eb8c0b8004dd5981780098188011129998168008a5eb804c8ccc888c8cc00400400c894ccc0cc004400c4c8cc0d4dd39981a9ba90063303537526eb8c0c8004cc0d4dd41bad30330014bd7019801801981b801181a8009bae302c0013756605a002660060066062004605e0022940dc7a441002302630273027302730273027302730270012302530263026001222323300500423002300b30253754002a666040603660446ea800448c06cccc018dd5980518121baa001375c601260486ea800cdd7180518121baa003123371090001998031bab300a302437540026eb8c024c090dd50019bae300a3024375400644646600200200644a666048002297ae01323253330223005002133027002330040040011330040040013028002302600122232533301f3019302137540022900009bad30253022375400264a66603e603260426ea80045300103d87a8000132330010013756604c60466ea8008894ccc094004530103d87a8000132323253330243371e00e6eb8c09800c4c04ccc0a4dd4000a5eb804cc014014008dd698130011814801181380099198008008021129998120008a6103d87a8000132323253330233371e00e6eb8c09400c4c048cc0a0dd3000a5eb804cc014014008dd598128011814001181300091299980e19b9000200114c0103d87980001533301c3371e0040022980103d87a800014c103d87b80003020301d375402426466446601a9213953686f756c642063616c6c206120506f6c6c4d616e6167657220696e7075742077697468204d657267655368617264732072656465656d6572003232533301f3375e004600c660486ea00112f5c02660126eb0c01cc088dd50099299981019baf004300830233754002266ebcc020c08cdd5180498119baa001300b30233754022294052819299980f980d00089919299981298140010a4c2c6eb4c098004c088dd50010a99980f980c80089919299981298140010a4c2c6eb4c098004c088dd50010a99980f980d80089919299981298140010a4c2c6eb4c098004c088dd50010b18101baa0013300a0013756601260406ea8044dd6981080098109811000980e9baa012374a90021180f8009180f180f80091191980080080191299980f0008a50132533301b3004302100214a2266006006002604200246038603a603a603a002460366038603860386038603860386038603860380024464a66602c602260306ea80044c070c064dd50008a9980ba48117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533301c00114c0103d87a80001323232533301b3375e00c603a006260146604000297ae0133005005002301d0023020002301e00130033301a0024bd701ba548008dd2a400044a666024666024002941288a9980980108008800980a98091baa00d14a0602860226ea800458c04cc050008c048004c038dd50008a4c26cac64a666014600a00226464a66602060260042649319299980698040008a99980898081baa00214985854ccc034c01c00454ccc044c040dd50010a4c2c2c601c6ea800458c044004c034dd50010a99980518020008991919192999809180a80109924ca66601c601260206ea80044c8c8c8c94ccc058c0640084c9265333012300d3014375400626464a66603060360042930b1bae3019001301537540062c2c6eb4c05c004c05c008c054004c044dd50008b0b180980098098011bad3011001300d37540042c60166ea8004c8c8c8c8c8c8c94ccc038c0240044c8c94ccc050c05c0084c9265333010300b3012375400226464646464646464646464646464646464646464646464646464a66605c606200426464649318100099929998161813800899192999819181a80109924ca66605c605260606ea80044c8c8c8c94ccc0d8c0e40084c8c9263303000225333034302f303637540022646464646464a66607c60820042930b1bad303f001303f002375c607a002607a0046eb8c0ec004c0dcdd50008b18148018b1bac303700130370023035001303137540022c2c6066002605e6ea805454ccc0b0c09800454ccc0c0c0bcdd500a8a4c2c2c605a6ea8050c94ccc0acc0980044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc11cc1280084c8c8c8c8c8c8c8c8c8c8c926304200b304100c304000d303f00e303e00f303d010303c011303b012303a013303c0143039015163048001304800230460013046002304400130440023042001304200230400013040002303e001303e002303c001303c002303a001303a002303800130380023036001303600230340013034002375c6064002605c6ea805854ccc0acc0940044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc11cc1280084c8c8c8c8c8c8c8c8c8c8c926304200b304100c304000d303f00e303e00f303d010303c011303b012303a013303c014325333044303f00113232533304a304d002132498c0ec00458c12c004c11cdd500b0a999822181f000899192999825182680109924c60780022c6096002608e6ea805858c114dd500a8b1824000982400118230009823001182200098220011821000982100118200009820001181f000981f001181e000981e001181d000981d001181c000981c001181b000981b001181a000981a0011bae3032001302e375402c2a666056604e00226464a6660626068004264932999816981418179baa0011323232323232323232323232323232323232323253330453048002132498c0d802c58dd6982300098230011bad30440013044002375a608400260840046eb4c100004c100008dd6981f000981f001181e000981e0011bad303a001303a002375a607000260700046eb4c0d8004c0d8008dd6981a00098181baa00116163032001302e375402c2a66605666e1d200600113232533303130340021324994ccc0b4c0a0c0bcdd5000899191919299981a981c00109924c6605c00246464a666068605e606c6ea80044c8c94ccc0e8c0f400852616375c6076002606e6ea800458c0d8008dd7181a0008b1bab30360013036002375a606800260606ea80045858c0c8004c0b8dd500b0a99981599b87480200044c8c94ccc0c4c0d000852616375c6064002605c6ea805858c0b0dd500a8b1bad302f001302f002375a605a002605a0046eb4c0ac004c0ac008dd6981480098148011bad30270013027002375a604a002604a0046eb4c08c004c08c008dd698108009810801180f800980f801180e800980e801180d800980d8011bae30190013019002375a602e00260266ea80045858c054004c044dd50060a999807180400089919299980a180b80109924ca666020601660246ea80044c8c8c8c8c8c8c8c94ccc070c07c0084c8c9263010002300c00516301d001301d002375a60360026036004603200260320046eb4c05c004c04cdd50008b0b180a80098089baa00c16300f37540164a66601a6010601e6ea80044c8c8c8c94ccc054c06000852616375a602c002602c0046eb4c050004c040dd50008b12999806180398071baa0011323253330123015002149858dd6980980098079baa001162533300b3006300d375400226464a66602260280042649318028008b180900098071baa001162533300a3005300c3754002264646464a666024602a0042646493192999808180580089919299980b180c80109924c64a666026601c00226464a66603260380042649318070008b180d000980b1baa00215333013300d0011323232323232533301d3020002149858dd6980f000980f0011bad301c001301c002375a6034002602c6ea800858c050dd50008b180b80098099baa00315333010300a00115333014301337540062930b0b18089baa002300700316301300130130023011001300d37540022c4a666012600860166ea80044c8c8c8c94ccc044c05000852616375c602400260240046eb8c040004c030dd50008b1192999804980200089919299980798090010a4c2c6eb8c040004c030dd50010a999804980180089919299980798090010a4c2c6eb8c040004c030dd50010b18051baa001370e90011b8748000dc3a400844646600200200644a66601600229309919801801980780118019806800ab9a5738aae7555cf2ab9f5740ae855d11"
2543
+ };
2544
+ var mkPollShardValidator = (params) => {
2545
+ return {
2546
+ type: pollShardValidatorData.type,
2547
+ script: applyParamsToScript9(pollShardValidatorData.cborHex, [
2548
+ castPollShardParams(params)
2549
+ ])
2550
+ };
2551
+ };
2552
+ var mkPollShardValidatorFromSP = (params) => {
2553
+ return {
2554
+ type: pollShardValidatorData.type,
2555
+ script: applyParamsToScript9(pollShardValidatorData.cborHex, [
2556
+ castPollShardParams({
2557
+ pollToken: fromSystemParamsAsset(params.pollToken),
2558
+ stakingToken: fromSystemParamsAsset(params.stakingToken),
2559
+ indyAsset: fromSystemParamsAsset(params.indyAsset),
2560
+ stakingValHash: params.stakingValHash
2561
+ })
2562
+ ])
2563
+ };
2564
+ };
2565
+
2566
+ // src/scripts/poll-manager-validator.ts
2567
+ import {
2568
+ applyParamsToScript as applyParamsToScript10
2569
+ } from "@lucid-evolution/lucid";
2570
+
2571
+ // src/types/indigo/poll-manager.ts
2572
+ import { Data as Data18 } from "@lucid-evolution/lucid";
2573
+ var PollManagerParamsSchema = Data18.Object({
2574
+ govNFT: AssetClassSchema,
2575
+ pollToken: AssetClassSchema,
2576
+ upgradeToken: AssetClassSchema,
2577
+ indyAsset: AssetClassSchema,
2578
+ govExecuteValHash: Data18.Bytes(),
2579
+ pBiasTime: Data18.Integer(),
2580
+ shardValHash: Data18.Bytes(),
2581
+ treasuryValHash: Data18.Bytes(),
2582
+ initialIndyDistribution: Data18.Integer()
2583
+ });
2584
+ var PollManagerParams = PollManagerParamsSchema;
2585
+ function castPollManagerParams(params) {
2586
+ return Data18.castTo(params, PollManagerParams);
2587
+ }
2588
+
2589
+ // src/scripts/poll-manager-validator.ts
2590
+ var pollManagerValidatorData = {
2591
+ type: "PlutusV2",
2592
+ description: "Generated by Aiken",
2593
+ cborHex: "59166859166501000032323232323232322232323232322322533300b323232533300e300830103754002264a66601e601260226ea80344c8c8c8c8c8c8c8c8c8c94c8ccc068c054c070dd50090999191919191919191911919299981518168010991919299981698180010992999815181218161baa00113232533303030330021323232533302f3301f4911d496e76616c696420696e707574206265696e672076616c696461746564003375e042602e60646ea802854ccc0bccc07d2401225468652070726f706f73616c206578636565647320766f74696e6720706572696f64003322325333032302c30343754002264a66606664a666070606e0022a666068605c606c002294454ccc0d0c0bcc0d80045280b0b1baa301c303637546038606c6ea80104cdc4000801899b89001003375a6070606a6ea8004528180c981a1baa301a30343754004602060646ea808cdd6980898191baa0201533302f3301f49011c54686520706f6c6c206f757470757420697320696e636f7272656374003333300e3758602260646ea808cc074cc0d00252f5c0602c66068603a6606864603e6606a606c0026606a64a666062605860666ea80384c080cc0d8dd419b80375a603260686ea800400cc0e0c0d0dd5000898101981b181b981a1baa00133036375066e00dd6980d181a1baa0010034bd70180c98199baa021303730370013032375404097ae04bd701bab301830323754603060646ea8029300103d87980001533302f3301f4910e4d697865642076657273696f6e73003375e602e60646ea8c05cc0c8dd5180c18191baa007301d33034301a3032375405c97ae01533302f3301f49127546865207472616e73616374696f6e206d757374206265207369676e6564206279206f776e6572003232330010013758606e6070607060706070607060706070607060686ea8094894ccc0d8004528099299981999b8f375c607200400829444cc00c00c004c0e4004dd7180b98191baa0041533302f3301f4911a5573657220766f74656420666f7220706f6c6c206265666f72650033302f3300d002375a602e60646ea8081282511533302f3301f491124d757374206d696e74206e6f20746f6b656e003375e6e98c8cc004004dd5981b181b981b981b981b98199baa02422533303500114bd6f7b630099191919299981a980a801080189981d19bb037520046e98004cc01801800cdd5981b8019bae3035002303900230370014c0101a0001533302f3301f491245374616b696e67506f736974696f6e206d757374207570646174652070726f7065726c79003333300e3758602260646ea808cc074cc0d0c078cc0d0c074cc0d0c068c0c8dd501725eb80cc0d130103d87a80004bd7025eb80c058cc0d0c074cc0d0c8c07ccc0d4c0d8004cc0d4dd319912999819198080028010991980080080311299981c0008a5eb7bdb1804cc0e4c8c94ccc0d8cdc3800803099bb0375000200a20046eb4c0dc004c0e8004cc008008c0ec0044c8c8cc00400401c894ccc0e4004400c4cc0e8c0ec004cc008008c0f0004cc0dccdd81ba80020014bd6f7b6301bad301830333754042603e6606a6ea0008cc0d4c048c0ccdd5010a5eb80c0dcc0dc004c0c8dd500225eb812f5c06eacc060c0c8dd5180c18191baa0074c0103d87a800013301f4901275374616b696e6720506f736974696f6e206d75737420757365204c6f636b2072656465656d65720032323375e004980103d87e8000325333031302c001132325333037303a002149858dd7181c000981a1baa00215333031302b00115333035303437540042930b0a99981898168008a99981a981a1baa00214985854ccc0c4cdc3a400c00226464a66606e60740042930b1bad3038001303437540042a66606266e1d200800115333035303437540042930b0a99981899b874802800454ccc0d4c0d0dd50010a4c2c2a66606266e1d200c00115333035303437540042930b0b18191baa0013301c30173032375400e6eacc06cc0c8dd50118a5014a029405280a5014a02940528199119980a8011bae3018303337540026eb8c064c0ccdd50009bab301730313754602e60626ea8018c040c0c4dd501699192999817981498189baa001132323300100100422533303600114bd6f7b63009919299981a19b88005375a60746076606e6ea8c0dc0084cc0e4008cc0100100044cc010010004c0e8008c0e0004dd6981a98191baa00116301630313754602c60626ea8c03cc0c4dd50111bab301630303754004a666058604e605c6ea80044c8c8c8c8c8c94ccc0d8c0e40084c8c9265333033302e3035375400426464a66607260780042930b1bad303a001303637540042c6605e00646464a66606a6060606e6ea80044c8c8c8c94ccc0f4c10000852616375a607c002607c0046eb4c0f0004c0e0dd50008b181b8011bad303500116303700130370023756606a002606a0046eb8c0cc004c0bcdd50008b0b181880098169baa0011632533302a3026302c375400226060605a6ea800454cc0ad241134e6f7420616e20696e6c696e6520646174756d0016300b302c3754602460586ea800458c0b8004ccc028dd6180798151baa01b3010302a375404c98103d8798000300e30293754601e60526ea800458c0ac004ccc01cdd6180618139baa018300c3027375404698103d8798000225333024301f30263754646600200200644a666054002298103d87a80001323253330283370e6eb4c0a80080144c05ccc0b4dd399816981500119816981580125eb812f5c0266008008002605c00460580022944528111111980819805002a999813181098141baa00413223375e602060566ea8c040c0acdd5000801181618149baa00413223375e602060566ea8004008c0b0c0a4dd50021299981399baf3009302a3754002008264a666058002294454ccc0b0c0bc0044c8c8c94ccc0acc02cdd718188018a99981598058008a999815981318169baa0061533302b337129000001099b89002482026fb808528099b89480000085280a50375c606060620046eb4c0bcc0c0c0c0004dd618170008a503233001001323330010013756602460586ea800cc8cc004004018894ccc0bc00452f5bded8c02646606266ec0dd49bae302e001374c64660020026eacc0c0008894ccc0c800452f5bded8c02646606866ec0dd49bae3031001375066e052000375a606400266006006606c00460680026600600660660046062002444a66605e004200226466600800860660066644646600200200a44a66606800226606a66ec0dd48021ba60034bd6f7b630099191919299981a19baf3301a0080024c0103d8798000133039337606ea4020dd30038028a99981a19b8f008002132533303530303037375400226607466ec0dd4804981d981c1baa0010041004325333035533303900114a229405300103d87a8000130243303a374c00297ae032333001001008002222533303b0021001132333004004303f00333223233001001005225333040001133041337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc100cdd799813004001260103d8798000133045337606ea4020dd40038028a99982019b8f0080021325333041303c3043375400226608c66ec0dd4804982398221baa0010041004325333041303c00114c103d87a80001303033046375000297ae03370000e00226608a66ec0dd48011ba800133006006003375a60840066eb8c100008c110008c108004dd7181d0009bad303b001303d002133039337606ea4008dd3000998030030019bab3036003375c60680046070004606c0026eb8c0b8004dd5981780098188011129998168008a5eb804c8ccc888c8cc00400400c894ccc0cc004400c4c8cc0d4dd39981a9ba90063303537526eb8c0c8004cc0d4dd41bad30330014bd7019801801981b801181a8009bae302c0013756605a002660060066062004605e0022940dc7a441002302630273027302730273027302730270012302530263026001222323300500423002300b30253754002a666040603660446ea800448c06cccc018dd5980518121baa001375c601260486ea800cdd7180518121baa003123371090001998031bab300a302437540026eb8c024c090dd50019bae300a3024375400644646600200200644a666048002297ae01323253330223005002133027002330040040011330040040013028002302600122232533301f3019302137540022900009bad30253022375400264a66603e603260426ea80045300103d87a8000132330010013756604c60466ea8008894ccc094004530103d87a8000132323253330243371e00e6eb8c09800c4c04ccc0a4dd4000a5eb804cc014014008dd698130011814801181380099198008008021129998120008a6103d87a8000132323253330233371e00e6eb8c09400c4c048cc0a0dd3000a5eb804cc014014008dd598128011814001181300091299980e19b9000200114c0103d87980001533301c3371e0040022980103d87a800014c103d87b80003020301d375402426466446601a9213953686f756c642063616c6c206120506f6c6c4d616e6167657220696e7075742077697468204d657267655368617264732072656465656d6572003232533301f3375e004600c660486ea00112f5c02660126eb0c01cc088dd50099299981019baf004300830233754002266ebcc020c08cdd5180498119baa001300b30233754022294052819299980f980d00089919299981298140010a4c2c6eb4c098004c088dd50010a99980f980c80089919299981298140010a4c2c6eb4c098004c088dd50010a99980f980d80089919299981298140010a4c2c6eb4c098004c088dd50010b18101baa0013300a0013756601260406ea8044dd6981080098109811000980e9baa012374a90021180f8009180f180f80091191980080080191299980f0008a50132533301b3004302100214a2266006006002604200246038603a603a603a002460366038603860386038603860386038603860380024464a66602c602260306ea80044c070c064dd50008a9980ba48117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533301c00114c0103d87a80001323232533301b3375e00c603a006260146604000297ae0133005005002301d0023020002301e00130033301a0024bd701ba548008dd2a400044a666024666024002941288a9980980108008800980a98091baa00d14a0602860226ea800458c04cc050008c048004c038dd50008a4c26cac64a666014600a00226464a66602060260042649319299980698040008a99980898081baa00214985854ccc034c01c00454ccc044c040dd50010a4c2c2c601c6ea800458c044004c034dd50010a99980518020008991919192999809180a80109924ca66601c601260206ea80044c8c8c8c94ccc058c0640084c9265333012300d3014375400626464a66603060360042930b1bae3019001301537540062c2c6eb4c05c004c05c008c054004c044dd50008b0b180980098098011bad3011001300d37540042c60166ea8004c8c8c8c8c8c8c94ccc038c0240044c8c94ccc050c05c0084c9265333010300b3012375400226464646464646464646464646464646464646464646464646464a66605c606200426464649318100099929998161813800899192999819181a80109924ca66605c605260606ea80044c8c8c8c94ccc0d8c0e40084c8c9263303000225333034302f303637540022646464646464a66607c60820042930b1bad303f001303f002375c607a002607a0046eb8c0ec004c0dcdd50008b18148018b1bac303700130370023035001303137540022c2c6066002605e6ea805454ccc0b0c09800454ccc0c0c0bcdd500a8a4c2c2c605a6ea8050c94ccc0acc0980044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc11cc1280084c8c8c8c8c8c8c8c8c8c8c926304200b304100c304000d303f00e303e00f303d010303c011303b012303a013303c0143039015163048001304800230460013046002304400130440023042001304200230400013040002303e001303e002303c001303c002303a001303a002303800130380023036001303600230340013034002375c6064002605c6ea805854ccc0acc0940044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc11cc1280084c8c8c8c8c8c8c8c8c8c8c926304200b304100c304000d303f00e303e00f303d010303c011303b012303a013303c014325333044303f00113232533304a304d002132498c0ec00458c12c004c11cdd500b0a999822181f000899192999825182680109924c60780022c6096002608e6ea805858c114dd500a8b1824000982400118230009823001182200098220011821000982100118200009820001181f000981f001181e000981e001181d000981d001181c000981c001181b000981b001181a000981a0011bae3032001302e375402c2a666056604e00226464a6660626068004264932999816981418179baa0011323232323232323232323232323232323232323253330453048002132498c0d802c58dd6982300098230011bad30440013044002375a608400260840046eb4c100004c100008dd6981f000981f001181e000981e0011bad303a001303a002375a607000260700046eb4c0d8004c0d8008dd6981a00098181baa00116163032001302e375402c2a66605666e1d200600113232533303130340021324994ccc0b4c0a0c0bcdd5000899191919299981a981c00109924c6605c00246464a666068605e606c6ea80044c8c94ccc0e8c0f400852616375c6076002606e6ea800458c0d8008dd7181a0008b1bab30360013036002375a606800260606ea80045858c0c8004c0b8dd500b0a99981599b87480200044c8c94ccc0c4c0d000852616375c6064002605c6ea805858c0b0dd500a8b1bad302f001302f002375a605a002605a0046eb4c0ac004c0ac008dd6981480098148011bad30270013027002375a604a002604a0046eb4c08c004c08c008dd698108009810801180f800980f801180e800980e801180d800980d8011bae30190013019002375a602e00260266ea80045858c054004c044dd50060a999807180400089919299980a180b80109924ca666020601660246ea80044c8c8c8c8c8c8c8c94ccc070c07c0084c8c9263010002300c00516301d001301d002375a60360026036004603200260320046eb4c05c004c04cdd50008b0b180a80098089baa00c16300f37540164a66601a6010601e6ea80044c8c8c8c94ccc054c06000852616375a602c002602c0046eb4c050004c040dd50008b12999806180398071baa0011323253330123015002149858dd6980980098079baa001162533300b3006300d375400226464a66602260280042649318028008b180900098071baa001162533300a3005300c3754002264646464a666024602a0042646493192999808180580089919299980b180c80109924c64a666026601c00226464a66603260380042649318070008b180d000980b1baa00215333013300d0011323232323232533301d3020002149858dd6980f000980f0011bad301c001301c002375a6034002602c6ea800858c050dd50008b180b80098099baa00315333010300a00115333014301337540062930b0b18089baa002300700316301300130130023011001300d37540022c4a666012600860166ea80044c8c8c8c94ccc044c05000852616375c602400260240046eb8c040004c030dd50008b1192999804980200089919299980798090010a4c2c6eb8c040004c030dd50010a999804980180089919299980798090010a4c2c6eb8c040004c030dd50010b18051baa001370e90011b8748000dc3a400844646600200200644a66601600229309919801801980780118019806800ab9a5738aae7555cf2ab9f5740ae855d11"
2594
+ };
2595
+ var mkPollManagerValidator = (params) => {
2596
+ return {
2597
+ type: pollManagerValidatorData.type,
2598
+ script: applyParamsToScript10(pollManagerValidatorData.cborHex, [
2599
+ castPollManagerParams(params)
2600
+ ])
2601
+ };
2602
+ };
2603
+ var mkPollManagerValidatorFromSP = (params) => {
2604
+ return {
2605
+ type: pollManagerValidatorData.type,
2606
+ script: applyParamsToScript10(pollManagerValidatorData.cborHex, [
2607
+ castPollManagerParams({
2608
+ govNFT: fromSystemParamsAsset(params.govNFT),
2609
+ pollToken: fromSystemParamsAsset(params.pollToken),
2610
+ upgradeToken: fromSystemParamsAsset(params.upgradeToken),
2611
+ indyAsset: fromSystemParamsAsset(params.indyAsset),
2612
+ govExecuteValHash: params.govExecuteValHash,
2613
+ pBiasTime: BigInt(params.pBiasTime),
2614
+ shardValHash: params.shardsValHash,
2615
+ treasuryValHash: params.treasuryValHash,
2616
+ initialIndyDistribution: BigInt(params.initialIndyDistribution)
2617
+ })
2618
+ ])
2619
+ };
2620
+ };
2621
+
2622
+ // src/types/indigo/execute.ts
2623
+ import { Data as Data19 } from "@lucid-evolution/lucid";
2624
+ var ExecuteParamsSchema = Data19.Object({
2625
+ govNFT: AssetClassSchema,
2626
+ upgradeToken: AssetClassSchema,
2627
+ iAssetToken: AssetClassSchema,
2628
+ stabilityPoolToken: AssetClassSchema,
2629
+ versionRecordToken: AssetClassSchema,
2630
+ cdpValHash: Data19.Bytes(),
2631
+ sPoolValHash: Data19.Bytes(),
2632
+ versionRegistryValHash: Data19.Bytes(),
2633
+ treasuryValHash: Data19.Bytes(),
2634
+ indyAsset: AssetClassSchema
2635
+ });
2636
+ var ExecuteParams = ExecuteParamsSchema;
2637
+ function castExecuteParams(params) {
2638
+ return Data19.castTo(params, ExecuteParams);
2639
+ }
2640
+
2641
+ // src/types/indigo/lrp.ts
2642
+ import { Data as Data20 } from "@lucid-evolution/lucid";
2643
+ var LRPParamsSchema = Data20.Object({
2644
+ versionRecordToken: AssetClassSchema,
2645
+ iassetNft: AssetClassSchema,
2646
+ iassetPolicyId: Data20.Bytes(),
2647
+ minRedemptionLovelacesAmt: Data20.Integer()
2648
+ });
2649
+ var LRPParams = LRPParamsSchema;
2650
+ var LRPDatumSchema = Data20.Object({
2651
+ owner: Data20.Bytes(),
2652
+ iasset: Data20.Bytes(),
2653
+ maxPrice: OnChainDecimalSchema,
2654
+ lovelacesToSpend: Data20.Integer()
2655
+ });
2656
+ var LRPDatum = LRPDatumSchema;
2657
+ var LRPRedeemerSchema = Data20.Enum([
2658
+ Data20.Object({ Redeem: Data20.Object({ continuingOutputIdx: Data20.Integer() }) }),
2659
+ Data20.Object({
2660
+ RedeemAuxiliary: Data20.Object({
2661
+ continuingOutputIdx: Data20.Integer(),
2662
+ mainRedeemOutRef: OutputReferenceSchema,
2663
+ asset: Data20.Bytes(),
2664
+ assetPrice: OnChainDecimalSchema,
2665
+ redemptionReimbursementPercentage: OnChainDecimalSchema
2666
+ })
2667
+ }),
2668
+ Data20.Literal("Cancel"),
2669
+ Data20.Literal("UpgradeVersion")
2670
+ ]);
2671
+ var LRPRedeemer = LRPRedeemerSchema;
2672
+ function parseLrpDatum(datum) {
2673
+ return Data20.from(datum, LRPDatum);
2674
+ }
2675
+ function serialiseLrpDatum(datum) {
2676
+ return Data20.to(datum, LRPDatum);
2677
+ }
2678
+ function serialiseLrpRedeemer(redeemer) {
2679
+ return Data20.to(redeemer, LRPRedeemer);
2680
+ }
2681
+ function castLrpParams(params) {
2682
+ return Data20.castTo(params, LRPParams);
2683
+ }
2684
+
2685
+ // src/contracts/lrp.ts
2686
+ import {
2687
+ addAssets as addAssets3
2688
+ } from "@lucid-evolution/lucid";
2689
+ import { match as match5, P as P5 } from "ts-pattern";
2690
+ import { unzip, zip } from "fp-ts/lib/Array";
2691
+ import { reduceWithIndex } from "fp-ts/lib/Array";
2692
+
2693
+ // src/helpers/price-oracle-helpers.ts
2694
+ import {
2695
+ slotToUnixTime,
2696
+ unixTimeToSlot
2697
+ } from "@lucid-evolution/lucid";
2698
+ function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
2699
+ const validateFrom = slotToUnixTime(network, currentSlot - 1);
2700
+ const defaultValidateTo = validateFrom + biasTime;
2701
+ const cappedValidateTo = slotToUnixTime(
2702
+ network,
2703
+ unixTimeToSlot(network, oracleExpiration) - 1
2704
+ );
2705
+ const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
2706
+ return {
2707
+ validFrom: validateFrom,
2708
+ validTo: isOracleActuallyExpired ? defaultValidateTo : Math.min(defaultValidateTo, cappedValidateTo)
2709
+ };
2710
+ }
2711
+
2712
+ // src/contracts/lrp.ts
2713
+ var MIN_UTXO_COLLATERAL_AMT = 2000000n;
2714
+ async function openLrp(assetTokenName, lovelacesAmt, maxPrice, lucid, lrpScriptHash, network, lrpStakeCredential) {
2715
+ const [ownPkh, _] = await addrDetails(lucid);
2716
+ const newDatum = {
2717
+ owner: ownPkh.hash,
2718
+ iasset: assetTokenName,
2719
+ maxPrice,
2720
+ lovelacesToSpend: lovelacesAmt
2721
+ };
2722
+ return lucid.newTx().pay.ToContract(
2723
+ createScriptAddress(network, lrpScriptHash, lrpStakeCredential),
2724
+ {
2725
+ kind: "inline",
2726
+ value: serialiseLrpDatum(newDatum)
2727
+ },
2728
+ { lovelace: lovelacesAmt + MIN_UTXO_COLLATERAL_AMT }
2729
+ );
2730
+ }
2731
+ async function cancelLrp(lrpOutRef, lrpRefScriptOutRef, lucid) {
2732
+ const ownAddr = await lucid.wallet().address();
2733
+ const lrpScriptRefUtxo = matchSingle(
2734
+ await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2735
+ (_) => new Error("Expected a single LRP Ref Script UTXO")
2736
+ );
2737
+ const lrpUtxo = matchSingle(
2738
+ await lucid.utxosByOutRef([lrpOutRef]),
2739
+ (_) => new Error("Expected a single LRP UTXO.")
2740
+ );
2741
+ return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSigner(ownAddr);
2742
+ }
2743
+ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, priceOracleParams, network) {
2744
+ const lrpScriptRefUtxo = matchSingle(
2745
+ await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2746
+ (_2) => new Error("Expected a single LRP Ref Script UTXO")
2747
+ );
2748
+ const priceOracleUtxo = matchSingle(
2749
+ await lucid.utxosByOutRef([priceOracleOutRef]),
2750
+ (_2) => new Error("Expected a single price oracle UTXO")
2751
+ );
2752
+ const iassetUtxo = matchSingle(
2753
+ await lucid.utxosByOutRef([iassetOutRef]),
2754
+ (_2) => new Error("Expected a single IAsset UTXO")
2755
+ );
2756
+ const iassetDatum = parseIAssetDatum(getInlineDatumOrThrow(iassetUtxo));
2757
+ const [lrpsToRedeemOutRefs, lrpRedemptionIAssetAmt] = unzip(redemptionLrpsData);
2758
+ const priceOracleDatum = parsePriceOracleDatum(
2759
+ getInlineDatumOrThrow(priceOracleUtxo)
2760
+ );
2761
+ const redemptionLrps = await lucid.utxosByOutRef(lrpsToRedeemOutRefs).then((val) => zip(val, lrpRedemptionIAssetAmt));
2762
+ const [[mainLrpUtxo, mainLrpRedemptionIAssetAmt], _] = match5(redemptionLrps).with(
2763
+ [P5._, ...P5.array()],
2764
+ ([[firstLrp, firstLrpIAssetAmt], ...rest]) => [[firstLrp, firstLrpIAssetAmt], rest]
2765
+ ).otherwise(() => {
2766
+ throw new Error("Expects at least 1 UTXO to redeem.");
2767
+ });
2768
+ const mainLrpDatum = parseLrpDatum(getInlineDatumOrThrow(mainLrpUtxo));
2769
+ const tx = reduceWithIndex(
2770
+ lucid.newTx(),
2771
+ (idx, acc, [lrpUtxo, redeemIAssetAmt]) => {
2772
+ const lovelacesForRedemption = ocdMul(
2773
+ {
2774
+ getOnChainInt: mainLrpRedemptionIAssetAmt
2775
+ },
2776
+ priceOracleDatum.price
2777
+ ).getOnChainInt;
2778
+ const reimburstmentLovelaces = calculateFeeFromPercentage2(
2779
+ iassetDatum.redemptionReimbursementPercentage,
2780
+ lovelacesForRedemption
2781
+ );
2782
+ const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
2783
+ return acc.collectFrom(
2784
+ [lrpUtxo],
2785
+ serialiseLrpRedeemer(
2786
+ idx === 0 ? { Redeem: { continuingOutputIdx: 0n } } : {
2787
+ RedeemAuxiliary: {
2788
+ continuingOutputIdx: BigInt(idx),
2789
+ mainRedeemOutRef: {
2790
+ txHash: { hash: mainLrpUtxo.txHash },
2791
+ outputIndex: BigInt(mainLrpUtxo.outputIndex)
2792
+ },
2793
+ asset: mainLrpDatum.iasset,
2794
+ assetPrice: priceOracleDatum.price,
2795
+ redemptionReimbursementPercentage: iassetDatum.redemptionReimbursementPercentage
2796
+ }
2797
+ }
2798
+ )
2799
+ ).pay.ToContract(
2800
+ lrpUtxo.address,
2801
+ {
2802
+ kind: "inline",
2803
+ value: serialiseLrpDatum({
2804
+ ...lrpDatum,
2805
+ lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
2806
+ })
2807
+ },
2808
+ addAssets3(
2809
+ lrpUtxo.assets,
2810
+ mkLovelacesOf(-(lovelacesForRedemption - reimburstmentLovelaces)),
2811
+ mkAssetsOf(
2812
+ {
2813
+ currencySymbol: lrpParams.iassetPolicyId,
2814
+ tokenName: mainLrpDatum.iasset
2815
+ },
2816
+ redeemIAssetAmt
2817
+ )
2818
+ )
2819
+ );
2820
+ }
2821
+ )(redemptionLrps);
2822
+ const txValidity = oracleExpirationAwareValidity(
2823
+ lucid.currentSlot(),
2824
+ Number(priceOracleParams.biasTime),
2825
+ Number(priceOracleDatum.expiration),
2826
+ network
2827
+ );
2828
+ return lucid.newTx().validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
2829
+ }
2830
+
2831
+ // src/scripts/lrp-validator.ts
2832
+ import {
2833
+ applyParamsToScript as applyParamsToScript11
2834
+ } from "@lucid-evolution/lucid";
2835
+ var lrpValidatorData = {
2836
+ type: "PlutusV2",
2837
+ description: "Generated by Aiken",
2838
+ cborHex: "5917845917810100003232323232323232322223232323232322533300b323232533300e3008301137540022646464646464646464646464646464646464646464646464646464a666052604a0342646464646464646464646464a666074607a004264a66606c606060726ea80044c8c94ccc0f4c1000084c8c8c8c94ccc0f0c0e0c0fcdd50008991919299981f981d98211baa00113253330403302249110496e636f727265637420694173736574003371e6eb8c0acc110dd50049bae30253044375407c264a666082666444646604e921124861766520746f207573652072656465656d005333045301f3048375460906466600200203697bdb180103d87980000101a000222533304d002100113330030033050002323232533304b3375e606c609e6ea8c0d8c13cdd5181818279baa00300a1323232533304e304a001132533304f533304f00614a2266609e94528251153305149012343616e20757365206f6e6c7920612073696e676c652052656465656d20706572205478001613376066609e94530103d87a80004c0103d8798000374c6601600a0026eb4c154c148dd50018a99982718240008991919191919299982a299982a19982a19b8f375c60b6008024941288a51153330543330543375e004036941288a5113330543375e022002941288a9982b2492452656465656d417578207573657320696e636f727265637420617373657420737461747300161337606660a801698103d87a80004c0103d8798000374c6602001400a60b460b600460b200260b200260b060b00046eb4c158004c148dd50018a998282492d4578706563746564206f6e6c792052656465656d2072656465656d65727320666f72204c525020696e7075747300163050375400460880026604c606c609e6ea800c0644010dd59827001981198261baa304c002304f00214a2266608a9452825122323300100100322533304d00113304e337606ea000ccc125264c0103d87980004bd6f7b6300991919192999826181e299982619b8800700214c103d87980001533304c3371000400e2980103d87b800014c103d87a8000133052337606ea001ccc135264c103d87980000051533304c3370e00e004264a66609a609260a06ea80044cc14ccdd81ba80083304e32498c150c144dd5000a60103d8798000004100453304e49126436f6e74696e75696e67206f75747075747320646f75626c6520736174697366616374696f6e0016133052337606ea0008cc134005300103d87980003300600600332498c13c00cdd6982680118288011827800981618229baa004375c6058608a6ea8028c004c114dd50050999999981082000280100201f804180098229baa00a14a0460906092609260926092609260926092609260920022940c118c10cdd50008b1980e00780a981418209baa302230413754002608660806ea800458cc0600400b4c0580e0c94ccc0e8c0d8c0f4dd500089820981f1baa001132533303b32533303c3036303f3754002266e24dd6981098201baa002375a608660806ea800454cc0f924124496e636f7272656374207472616e73616374696f6e2076616c69646974792072616e676500163026303f37546040607e6ea802854cc0f52401174f7261636c652063616e27742062652065787069726564001613026303f37540026464004a666076606e607c6ea80044c8c8c8c94ccc110c11c0084c926303a00316375a608a002608a0046086002607e6ea800458c048c078c0f8dd5180f981f1baa325333040001153303d49012145787065637465642065786163746c79206f6e65206f7261636c6520696e707574001615333040304300113042001153303d49012145787065637465642065786163746c79206f6e65206f7261636c6520696e707574001633301300d3041303e37546082607c6ea8005300103d8798000301e303d375400464a666072606a60786ea80084c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc168c1740084c8c8c8c8c8c8c8c8c8c8c8c926325333061305d001132325333068306b002149858dd7183480098329baa00d15333061305b001153330663065375401a2930b0b18319baa00c305a00f30590103058011305701230560133055014305401530530163052017301e018325333056305200113232533305d3060002132498c14c00458c178004c168dd500d0a99982b182800089919299982e983000109924ca6660b060a860b66ea80044c8c94ccc17cc1880084c9263022001163060001305c37540022c2c60bc00260b46ea806858c160dd500c8b182d800982d80119299982c182b8008a9998299826982b0008a5115333053304f305600114a02c2c6ea8c164004c164008c15c004c15c008c154004c154008c14c004c14c008c144004c144008c13c004c13c008c134004c134008c12c004c12c008c124004c124008c11c004c11c008c114004c114008c10c004c10c008dd71820800981e9baa00216253330393035303c3754002264646464a666084608a0042930b1bae30430013043002375c6082002607a6ea80045858c0f8004c0e8dd50008b1806980c981c9baa301a303937540022c607600266601800c6030606e6ea80c9300103d879800037566072607460740046070002607060706070607060700046eb0c0d8004c0d8008dd6181a000981a0011bac3032001302e375403c6eb4c0c0c0b4dd50130a999814981180d099191919191919191919191919191919299981c981a981e1baa0011323232533303c3038303f375400226464a66607c607460826ea80044c8c94ccc114c1200084c94ccc104c0f4c110dd500089929998211981224810c57726f6e6720696173736574003371e0286eb8c09cc118dd50200a999821198122491e52656465656d207574786f2066726f6d2077726f6e672061646472657373003375e605a608c6ea8c0b4c118dd5181398231baa006302d30463754010266666660440820120020100800240222940528182418229baa001163301e00b01616375a608c00260846ea800458cc06004401cc10cc100dd50008b1980c0040079812981f1baa301f303e37540026080607a6ea800458cc0540140a8c04c0d4dd5981e981f181f181f181f181f181f181f0011bac303c001303c303c00237586074002606c6ea8098c0e0c0e4008c0dc004c0dc008dd7181a800981a801181980098198011bad3031001302d375404c264a66605460460362646601a92011754582069736e74207369676e6564206279206f776e657200330023758606460666066606660666066606660666066605e6ea807cdd7180b18179baa02930060281333232322232323232325333034303030373754002264a66606a605e60706ea80044c8c8c94ccc0f4c1000084c8c8c94ccc0ecc0dcc0f8dd500089980e99807998209ba937309201084d697373696e6720003304137526e60038cc104dd49b984901172075706772616465206d696e74696e6720706f6c696379004bd70249003301230103302400948900375c6084607e6ea800454cc0f4cc03ccc104dd49b98491084d697373696e6720003304137526e60038cc104dd49b9849010d20757067726164652070617468004bd70249001632533303b3035303e3754002298103d87a8000130233304137526eb8c0fcc8cdd81821800982198220009bac3042303f375400297ae0323300100137566040607e6ea800c894ccc1040045300103d87a800013232533303e3371e6eb8c1040080244c098cc110dd399822182080119822182100125eb812f5c0266008008002608a0046086002a666072606a60786ea80044c8c8c8c94ccc108c1140084c926323300100100222533304400114984c8cc00c00cc120008c8c8dd718228011bae30430013046001163756608600260860046eb4c104004c0f4dd50008b1808180e181e1baa301d303c37540022c607c00266601e00a01098103d8798000375c607860726ea800458c07cc0e0dd5180f981c1baa301930383754607660706ea800458cc040dd6181d0020129bab3039303a303a303a00237586070002607000260666ea808c88dcc991919980080080224410022253330370021001132333004004303b0035333033302f371a00426e600044cdc500119b8a00537300026e64dd7181c8011b98001300100122533303100114bd700998191817981980099801001181a000a49034c5250003015302e375405244646600200200644a66606400229404c94ccc0b8cdc79bae303500200414a2266006006002606a0024a666052604460586ea80044c0c0c0b4dd50008a99815a481134e6f7420616e20696e6c696e6520646174756d0016222323301500423002301130303754002a666054604c605a6ea800448c094ccc044dd5980818179baa001375c602c605e6ea800cdd7180818179baa00312300533301137566020605e6ea8004dd7180b18179baa003375c6020605e6ea800cdc4240004464a666050604860566ea80044c0bcc0b0dd50008a99815248117436f756c64206e6f742066696e642072656465656d6572001632323300100100322533302f00114c0103d87a80001323232533302d3375e00c60600062602a6606600297ae01330050050023030002303300230310013374a90011981680125eb8094ccc094c084c0a0dd5000899191919191919192999819181a80109924c60500062c6eb4c0cc004c0cc008c0c4004c0c4008dd7181780098178011bae302d001302937540022c44646600200200644a6660580022980103d87a80001323253330293375e6028605a6ea80080144c044cc0bc0092f5c02660080080026060004605c0026002002444a6660520042980103d87a800013232533302630220031300e3302c0024bd70099980280280099b8000348004c0b400cc0ac0088888888c8c8c94ccc0a8cc03124011e48617320746f2072656465656d206174206c6561737420746865206d696e00337126eb4c02cc0b8dd50050010a99981519806249124d617820707269636520657863656564656400337126eb4c054c0b8dd50029bad3015302e3754601c605c6ea801854ccc0a8cc0312411b52656465656d696e67206d6f7265207468616e20616c6c6f77656400337120046eb4c02cc0b8dd500309980624811757726f6e6720636f6e74696e75696e67206f75747075740033332222323300100133019005533302f302b30323754008264466ebcc070c0d4dd5180e181a9baa001002303630333754008264466ebcc070c0d4dd5000801181b18199baa00422533303500114a0264a66606264a66606466ebcc058c0d8dd5000803099299981c0008a5115333038303b001132323253330363371e6eb8c0f400d22100153330363371e00291010015333036303230393754980103d87a800015333036337129000001099b89002482026fb808528099b89480000085280a50375c6078607a0046eb4c0ecc0f0c0f0004dd6181d0008a503233001001323330010013756603260706ea800cc8cc004004020894ccc0ec00452f5bded8c02646607a66ec0dd49bae303a001374c64660020026eacc0f0008894ccc0f800452f5bded8c02646608066ec0dd49bae303d001375066e052000375a607c002660060066084004608000266006006607e004607a002444a6660760042002264666008008607e0066666604a0046eb8c0e8004dd5981d80091119299981d98140008a60103d87a80001302333041374c00297ae0323330010010030022225333042002100113233300400430460033333302d002375c60820026eb4c108004888c94ccc108c0f80045300103d87a80001302a33048375000297ae0337000040020546088004046607a00444a666072002297ae0132333222323300100100322533303f001100313233041374e660826ea4018cc104dd49bae303e0013304137506eb4c0fc0052f5c066006006608600460820026eb8c0e0004dd5981c80099801801981e801181d8008a50303800214a226600600600260700026606001097ae03374a900119818003a5eb80cdd2a400866060646460286606460660046606460660026606460666068002660646ea0cdc09bad300d3030375401000897ae03033001302e375400c97ae033330113333011330133756601e605c6ea8c03cc0b8dd5004a44100488100488100001375c601c605c6ea8028dd7180798171baa00600314a0294052819b803370266601e6eacc038c0b4dd5180718169baa00848810048810000153330293371200290000a400026eb4c050c0b4dd51808998179ba83370666e08dd6980a18169baa3300c30113302f375000297ae00034820225e8dd6980a18169baa30113302f375066e0920c8014820225e92f5c097ae0375a602660586ea8cc02cc040cc0b8dd4000a5eb8000ccdc09998069bab300c302b375400a6eb8c02cc0acdd50039bae300c302b375400666601a6eacc030c0acdd5180618159baa006375c601660566ea801cdd7180618159baa003230273028302830280012253330203330200014a094454cc0880084004400488c01ccc094dd419b83337046eb4c028c08cdd50011bad300a30233754002904044bd25eb808c090c094c0940048c08cc090004888c94ccc078c060c084dd50008a400026eb4c094c088dd500099299980f180c18109baa00114c103d87a8000132330010013756604c60466ea8008894ccc094004530103d87a8000132323253330233371e00e6eb8c09800c4c02ccc0a4dd4000a5eb804cc014014008dd698130011814801181380099198008008021129998120008a6103d87a8000132323253330223371e00e6eb8c09400c4c028cc0a0dd3000a5eb804cc014014008dd59812801181400118130009111299980e980c8008802099999805802001991900119198008008011129998128008a4c264a66604c002293099192999811980f98131baa3300f375c604c60540086eb8c0980084cc014014cc0a400800454cc0952401326b65797320696e206173736f63696174697665206c697374206172656e277420696e20617363656e64696e67206f726465720016302a0023028001302800133023337606ea4008dd4000a5eb7bdb180888c94ccc084c038004530103d87a80001300933027374c00297ae03333300f001005004222325333024302000114c103d87a80001300c3302a375000297ae0337000020040180126e95200022323300100100322533302000114bd6f7b630099191919299980f99b8f0070021003133025337606ea4008dd3000998030030019bab3022003375c60400046048004604400244646600200200644a66603e002297ae013232533301c300500213302200233004004001133004004001302300230210012301d001225333016337200040022980103d8798000153330163371e0040022980103d87a800014c103d87b80002533301900114a2294088888c8cc004004018894ccc0780044cc07ccdd81ba9006374c00a97adef6c60132323232533301d300d3300700a002133023337606ea4028dd30048028a99980e99b8f00a002132533301e301a3021375400226604866ec0dd4805981298111baa001004100433300800a009001133023337606ea4008dd3000998030030019bab3020003375c603c0046044004604000244444646600200200c44a66603a00226603c66ec0dd48031ba80054bd6f7b630099191919299980e18061980380500109981119bb037520146ea002401454ccc070cdc7805001099299980e980c98101baa001133023337606ea402cc090c084dd5000802080219980400500480089981119bb037520046ea0004cc01801800cdd6980f8019bae301d0023021002301f001375e98103d879800030123754018602a60246ea800458c050c054008c04c004c03cdd50008a4c26cac600200c464a666014600c00226464a66602260280042930b1bad3012001300e37540042a6660146008002264646464646464646464a666032603800426464649318088019808002299980a1808180b9baa007132323232533301d30200021324994ccc060c050c06cdd500189919299980f98110010a4c2c6eb8c080004c070dd50018b0b1bad301e001301e002301c0013018375400e2c2c60340026034004603000260300046eb8c058004c058008c050004c050008dd6980900098071baa0021533300a30030011533300f300e37540042930b0a99980519b874801800454ccc03cc038dd50010a4c2c2c60186ea8004dc3a40086e1d20022533300630023009375400226464a66601a60200042930b1bad300e001300a37540022c6e1d20005734ae6d5ce2ab9d5573caae7d5d02ba15745"
2839
+ };
2840
+ var mkLrpValidator = (params) => {
2841
+ return {
2842
+ type: lrpValidatorData.type,
2843
+ script: applyParamsToScript11(lrpValidatorData.cborHex, [
2844
+ castLrpParams(params)
2845
+ ])
2846
+ };
2847
+ };
2848
+
2849
+ // src/helpers/helper-txs.ts
2850
+ import {
2851
+ validatorToAddress as validatorToAddress6
2852
+ } from "@lucid-evolution/lucid";
2853
+
2854
+ // src/scripts/always-fail-validator.ts
2855
+ var alwaysFailValidator = {
2856
+ type: "PlutusV2",
2857
+ script: "587f010000323232323232232253330044a029309b2b19299980199b874800000454ccc018c014dd50010a4c2c2a66600666e1d2002001132325333008300a002149858dd7180400098029baa002153330033370e900200089919299980418050010a4c2c6010002600a6ea800858c00cdd5000ab9a5573aaae7955cfaba157441"
2858
+ };
2859
+
2860
+ // src/helpers/helper-txs.ts
2861
+ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
2862
+ const scriptAddr = validatorToAddress6(network, alwaysFailValidator);
2863
+ const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
2864
+ await lucid.awaitTx(txHash);
2865
+ return { txHash, outputIndex: 0 };
2866
+ }
1011
2867
  export {
2868
+ AccountAction,
2869
+ AccountActionSchema,
2870
+ AccountContent,
2871
+ AccountContentSchema,
2872
+ ActionReturnDatum,
2873
+ ActionReturnDatumSchema,
2874
+ Address,
2875
+ AddressSchema,
2876
+ AssetClassSchema,
2877
+ CDPContentSchema,
1012
2878
  CDPContract,
1013
- CDPCreatorContract,
1014
- CDPHelpers,
2879
+ CDPDatumSchema,
2880
+ CDPFeesSchema,
1015
2881
  CollectorContract,
2882
+ Credential,
2883
+ CredentialSchema,
2884
+ EpochToScaleToSum,
2885
+ EpochToScaleToSumSchema,
2886
+ ExecuteParams,
2887
+ FeedInterestOracleRedeemerSchema,
1016
2888
  GovContract,
2889
+ GovParams,
2890
+ IAssetContentSchema,
1017
2891
  IAssetHelpers,
1018
2892
  InterestOracleContract,
1019
- PriceOracleContract,
2893
+ InterestOracleDatumSchema,
2894
+ InterestOracleParamsSchema,
2895
+ LRPDatumSchema,
2896
+ LRPParamsSchema,
2897
+ LRPRedeemerSchema,
2898
+ ONE_SECOND,
2899
+ OracleAssetNftSchema,
2900
+ OutputReferenceSchema,
2901
+ PollManagerParams,
2902
+ PollShardParams,
2903
+ PriceOracleDatumSchema,
2904
+ PriceOracleParamsSchema,
2905
+ SPInteger,
2906
+ SPIntegerSchema,
2907
+ SnapshotEpochToScaleToSumContent,
2908
+ SnapshotEpochToScaleToSumContentSchema,
2909
+ StabilityPoolContent,
2910
+ StabilityPoolContentSchema,
2911
+ StabilityPoolContract,
2912
+ StabilityPoolDatum,
2913
+ StabilityPoolDatumSchema,
2914
+ StabilityPoolParams,
2915
+ StabilityPoolRedeemer,
2916
+ StabilityPoolRedeemerSchema,
2917
+ StabilityPoolSnapshot,
2918
+ StakingContract,
1020
2919
  TreasuryContract,
1021
- _cdpCreatorValidator,
2920
+ VerificationKeyHashSchema,
1022
2921
  _cdpValidator,
1023
2922
  _collectorValidator,
1024
- _interestOracleValidator,
1025
2923
  _treasuryValidator,
1026
2924
  addrDetails,
2925
+ addressFromBech32,
2926
+ addressToBech32,
1027
2927
  balance,
1028
2928
  calculateFeeFromPercentage,
2929
+ cancelLrp,
2930
+ castExecuteParams,
2931
+ castGovParams,
2932
+ castInterestOracleParams,
2933
+ castLrpParams,
2934
+ castPollManagerParams,
2935
+ castPollShardParams,
2936
+ castPriceOracleParams,
2937
+ castStabilityPoolParams,
2938
+ cdpCreatorValidator,
2939
+ createScriptAddress,
2940
+ fromSPInteger,
2941
+ fromSystemParamsAsset,
2942
+ getInlineDatumOrThrow,
1029
2943
  getRandomElement,
1030
2944
  loadSystemParamsFromFile,
1031
2945
  loadSystemParamsFromUrl,
2946
+ matchSingle,
2947
+ mkCDPCreatorValidator,
2948
+ mkCDPCreatorValidatorFromSP,
2949
+ mkInterestOracleValidator,
2950
+ mkLrpValidator,
2951
+ mkPollManagerValidator,
2952
+ mkPollManagerValidatorFromSP,
2953
+ mkPollShardValidator,
2954
+ mkPollShardValidatorFromSP,
2955
+ mkSPInteger,
1032
2956
  oneDay,
1033
2957
  oneHour,
2958
+ oneShotMintTx,
1034
2959
  oneYear,
1035
- scriptRef
2960
+ openLrp,
2961
+ parseAccountDatum,
2962
+ parseCDPDatum,
2963
+ parseGovDatum,
2964
+ parseIAssetDatum,
2965
+ parseInterestOracleDatum,
2966
+ parseLrpDatum,
2967
+ parsePriceOracleDatum,
2968
+ parseSnapshotEpochToScaleToSumDatum,
2969
+ parseStabilityPoolDatum,
2970
+ redeemLrp,
2971
+ runCreateScriptRefTx,
2972
+ runOneShotMintTx,
2973
+ scriptRef,
2974
+ serialiseCDPDatum,
2975
+ serialiseFeedInterestOracleRedeemer,
2976
+ serialiseGovDatum,
2977
+ serialiseIAssetDatum,
2978
+ serialiseInterestOracleDatum,
2979
+ serialiseLrpDatum,
2980
+ serialiseLrpRedeemer,
2981
+ serialisePriceOracleDatum,
2982
+ serialiseStabilityPoolDatum,
2983
+ serialiseStabilityPoolRedeemer,
2984
+ spAdd,
2985
+ spDiv,
2986
+ spMul,
2987
+ spSub,
2988
+ toSystemParamsAsset
1036
2989
  };