@lucid-evolution/provider 0.1.19 → 0.1.21
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.
- package/dist/index.cjs +443 -4
- package/dist/index.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +442 -4
- package/package.json +8 -5
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Blockfrost: () => Blockfrost,
|
|
34
|
+
Koios: () => Koios,
|
|
34
35
|
Kupmios: () => Kupmios,
|
|
35
36
|
Maestro: () => Maestro,
|
|
36
37
|
datumJsonToCbor: () => datumJsonToCbor
|
|
@@ -47,7 +48,7 @@ var import_utils = require("@lucid-evolution/utils");
|
|
|
47
48
|
// package.json
|
|
48
49
|
var package_default = {
|
|
49
50
|
name: "@lucid-evolution/provider",
|
|
50
|
-
version: "0.1.
|
|
51
|
+
version: "0.1.21",
|
|
51
52
|
description: "",
|
|
52
53
|
main: "./dist/index.js",
|
|
53
54
|
types: "./dist/index.d.ts",
|
|
@@ -67,7 +68,8 @@ var package_default = {
|
|
|
67
68
|
},
|
|
68
69
|
scripts: {
|
|
69
70
|
build: "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
70
|
-
clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
71
|
+
clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
72
|
+
test: "vitest run"
|
|
71
73
|
},
|
|
72
74
|
keywords: [],
|
|
73
75
|
author: "",
|
|
@@ -76,8 +78,9 @@ var package_default = {
|
|
|
76
78
|
"@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
|
|
77
79
|
},
|
|
78
80
|
dependencies: {
|
|
79
|
-
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
80
81
|
"@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
|
|
82
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
83
|
+
"@effect/schema": "^0.67.16",
|
|
81
84
|
"@lucid-evolution/core-types": "workspace:*",
|
|
82
85
|
"@lucid-evolution/core-utils": "workspace:*",
|
|
83
86
|
"@lucid-evolution/utils": "workspace:*"
|
|
@@ -85,7 +88,8 @@ var package_default = {
|
|
|
85
88
|
devDependencies: {
|
|
86
89
|
"@types/node": "^20.12.8",
|
|
87
90
|
tsup: "^8.0.2",
|
|
88
|
-
typescript: "^5.4.5"
|
|
91
|
+
typescript: "^5.4.5",
|
|
92
|
+
vitest: "^1.6.0"
|
|
89
93
|
}
|
|
90
94
|
};
|
|
91
95
|
|
|
@@ -843,9 +847,444 @@ var Maestro = class {
|
|
|
843
847
|
}
|
|
844
848
|
};
|
|
845
849
|
var lucid2 = package_default.version;
|
|
850
|
+
|
|
851
|
+
// src/koios/koios.ts
|
|
852
|
+
var S2 = __toESM(require("@effect/schema/Schema"), 1);
|
|
853
|
+
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
854
|
+
var import_utils4 = require("@lucid-evolution/utils");
|
|
855
|
+
|
|
856
|
+
// src/koios/schema.ts
|
|
857
|
+
var S = __toESM(require("@effect/schema/Schema"), 1);
|
|
858
|
+
var ProtocolParametersSchema = S.Struct({
|
|
859
|
+
epoch_no: S.Number,
|
|
860
|
+
min_fee_a: S.Number,
|
|
861
|
+
min_fee_b: S.Number,
|
|
862
|
+
max_block_size: S.Number,
|
|
863
|
+
max_tx_size: S.Number,
|
|
864
|
+
max_bh_size: S.Number,
|
|
865
|
+
key_deposit: S.BigInt,
|
|
866
|
+
pool_deposit: S.BigInt,
|
|
867
|
+
max_epoch: S.Number,
|
|
868
|
+
optimal_pool_count: S.Number,
|
|
869
|
+
influence: S.Number,
|
|
870
|
+
monetary_expand_rate: S.Number,
|
|
871
|
+
treasury_growth_rate: S.Number,
|
|
872
|
+
decentralisation: S.Number,
|
|
873
|
+
extra_entropy: S.NullOr(S.String),
|
|
874
|
+
protocol_major: S.Number,
|
|
875
|
+
protocol_minor: S.Number,
|
|
876
|
+
min_utxo_value: S.String,
|
|
877
|
+
min_pool_cost: S.String,
|
|
878
|
+
nonce: S.String,
|
|
879
|
+
block_hash: S.NullOr(S.String),
|
|
880
|
+
cost_models: S.Struct({
|
|
881
|
+
PlutusV1: S.Array(S.Number),
|
|
882
|
+
PlutusV2: S.Array(S.Number)
|
|
883
|
+
}),
|
|
884
|
+
price_mem: S.Number,
|
|
885
|
+
price_step: S.Number,
|
|
886
|
+
max_tx_ex_mem: S.BigIntFromNumber,
|
|
887
|
+
max_tx_ex_steps: S.BigIntFromNumber,
|
|
888
|
+
max_block_ex_mem: S.Number,
|
|
889
|
+
max_block_ex_steps: S.Number,
|
|
890
|
+
max_val_size: S.Number,
|
|
891
|
+
collateral_percent: S.Number,
|
|
892
|
+
max_collateral_inputs: S.Number,
|
|
893
|
+
coins_per_utxo_size: S.BigInt
|
|
894
|
+
});
|
|
895
|
+
var KoiosAssetSchema = S.Struct({
|
|
896
|
+
policy_id: S.String,
|
|
897
|
+
asset_name: S.NullOr(S.String),
|
|
898
|
+
fingerprint: S.String,
|
|
899
|
+
decimals: S.Number,
|
|
900
|
+
quantity: S.String
|
|
901
|
+
});
|
|
902
|
+
var KoiosUTxOSchema = S.Struct({
|
|
903
|
+
tx_hash: S.String,
|
|
904
|
+
tx_index: S.Number,
|
|
905
|
+
block_height: S.NullOr(S.Number),
|
|
906
|
+
value: S.String,
|
|
907
|
+
datum_hash: S.NullOr(S.String),
|
|
908
|
+
inline_datum: S.NullOr(
|
|
909
|
+
S.Struct({
|
|
910
|
+
bytes: S.String,
|
|
911
|
+
value: S.Object
|
|
912
|
+
})
|
|
913
|
+
),
|
|
914
|
+
reference_script: S.NullOr(
|
|
915
|
+
S.Struct({
|
|
916
|
+
hash: S.String,
|
|
917
|
+
size: S.Number,
|
|
918
|
+
type: S.String,
|
|
919
|
+
bytes: S.String,
|
|
920
|
+
value: S.NullOr(S.Object)
|
|
921
|
+
})
|
|
922
|
+
),
|
|
923
|
+
asset_list: S.Array(KoiosAssetSchema)
|
|
924
|
+
});
|
|
925
|
+
var KoiosAddressInfoSchema = S.Array(
|
|
926
|
+
S.NullishOr(
|
|
927
|
+
S.Struct({
|
|
928
|
+
address: S.String,
|
|
929
|
+
balance: S.String,
|
|
930
|
+
stake_address: S.NullOr(S.String),
|
|
931
|
+
script_address: S.Boolean,
|
|
932
|
+
utxo_set: S.Array(KoiosUTxOSchema)
|
|
933
|
+
})
|
|
934
|
+
)
|
|
935
|
+
);
|
|
936
|
+
var KoiosInputOutputSchema = S.Struct({
|
|
937
|
+
payment_addr: S.Struct({
|
|
938
|
+
bech32: S.String,
|
|
939
|
+
cred: S.String
|
|
940
|
+
}),
|
|
941
|
+
stake_addr: S.NullOr(S.String),
|
|
942
|
+
tx_hash: S.String,
|
|
943
|
+
tx_index: S.Number,
|
|
944
|
+
value: S.String,
|
|
945
|
+
datum_hash: S.NullOr(S.String),
|
|
946
|
+
inline_datum: S.NullOr(
|
|
947
|
+
S.Struct({
|
|
948
|
+
bytes: S.String,
|
|
949
|
+
value: S.Object
|
|
950
|
+
})
|
|
951
|
+
),
|
|
952
|
+
reference_script: S.NullOr(
|
|
953
|
+
S.Struct({
|
|
954
|
+
hash: S.String,
|
|
955
|
+
size: S.Number,
|
|
956
|
+
type: S.String,
|
|
957
|
+
bytes: S.String,
|
|
958
|
+
value: S.NullOr(S.Object)
|
|
959
|
+
})
|
|
960
|
+
),
|
|
961
|
+
asset_list: S.Array(KoiosAssetSchema)
|
|
962
|
+
});
|
|
963
|
+
var KoiosTxInfoSchema = S.Struct({
|
|
964
|
+
tx_hash: S.String,
|
|
965
|
+
block_hash: S.String,
|
|
966
|
+
block_height: S.Number,
|
|
967
|
+
epoch_no: S.Number,
|
|
968
|
+
epoch_slot: S.Number,
|
|
969
|
+
absolute_slot: S.Number,
|
|
970
|
+
tx_timestamp: S.Number,
|
|
971
|
+
tx_block_index: S.Number,
|
|
972
|
+
tx_size: S.Number,
|
|
973
|
+
total_output: S.String,
|
|
974
|
+
fee: S.String,
|
|
975
|
+
deposit: S.String,
|
|
976
|
+
invalid_before: S.NullOr(S.String),
|
|
977
|
+
invalid_after: S.NullOr(S.String),
|
|
978
|
+
collateral_inputs: S.NullOr(S.Array(KoiosInputOutputSchema)),
|
|
979
|
+
collateral_output: S.NullOr(KoiosInputOutputSchema),
|
|
980
|
+
reference_inputs: S.NullOr(S.Array(KoiosInputOutputSchema)),
|
|
981
|
+
inputs: S.Array(KoiosInputOutputSchema),
|
|
982
|
+
outputs: S.Array(KoiosInputOutputSchema),
|
|
983
|
+
withdrawals: S.NullOr(
|
|
984
|
+
S.Array(
|
|
985
|
+
S.Struct({
|
|
986
|
+
amount: S.String,
|
|
987
|
+
stake_addr: S.String
|
|
988
|
+
})
|
|
989
|
+
)
|
|
990
|
+
),
|
|
991
|
+
assets_minted: S.NullOr(S.Array(KoiosAssetSchema)),
|
|
992
|
+
metadata: S.NullOr(S.Object),
|
|
993
|
+
certificates: S.NullOr(
|
|
994
|
+
S.Array(
|
|
995
|
+
S.Struct({
|
|
996
|
+
index: S.Number,
|
|
997
|
+
type: S.String,
|
|
998
|
+
info: S.NullOr(S.Object)
|
|
999
|
+
})
|
|
1000
|
+
)
|
|
1001
|
+
),
|
|
1002
|
+
native_scripts: S.NullOr(
|
|
1003
|
+
S.Array(
|
|
1004
|
+
S.Struct({
|
|
1005
|
+
script_hash: S.String,
|
|
1006
|
+
script_json: S.Object
|
|
1007
|
+
})
|
|
1008
|
+
)
|
|
1009
|
+
),
|
|
1010
|
+
plutus_contracts: S.NullOr(
|
|
1011
|
+
S.Array(
|
|
1012
|
+
S.Struct({
|
|
1013
|
+
address: S.String,
|
|
1014
|
+
spends_inputs: S.NullOr(
|
|
1015
|
+
S.Struct({
|
|
1016
|
+
tx_hash: S.String,
|
|
1017
|
+
tx_index: S.Number
|
|
1018
|
+
})
|
|
1019
|
+
),
|
|
1020
|
+
script_hash: S.String,
|
|
1021
|
+
bytecode: S.String,
|
|
1022
|
+
size: S.Number,
|
|
1023
|
+
valid_contract: S.Boolean,
|
|
1024
|
+
input: S.Struct({
|
|
1025
|
+
redeemer: S.Struct({
|
|
1026
|
+
purpose: S.Literal("spend", "mint", "cert", "reward")
|
|
1027
|
+
})
|
|
1028
|
+
}),
|
|
1029
|
+
fee: S.String,
|
|
1030
|
+
unit: S.Struct({
|
|
1031
|
+
steps: S.String,
|
|
1032
|
+
mem: S.String
|
|
1033
|
+
}),
|
|
1034
|
+
datum: S.Struct({
|
|
1035
|
+
hash: S.NullOr(S.String),
|
|
1036
|
+
value: S.NullOr(S.Object)
|
|
1037
|
+
})
|
|
1038
|
+
})
|
|
1039
|
+
)
|
|
1040
|
+
)
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// src/koios/koios.ts
|
|
1044
|
+
var Koios = class {
|
|
1045
|
+
baseUrl;
|
|
1046
|
+
constructor(baseUrl) {
|
|
1047
|
+
this.baseUrl = baseUrl;
|
|
1048
|
+
}
|
|
1049
|
+
async getProtocolParameters() {
|
|
1050
|
+
const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
|
|
1051
|
+
(res) => res.json()
|
|
1052
|
+
);
|
|
1053
|
+
const param = S2.decodeUnknownSync(ProtocolParametersSchema)(result[0]);
|
|
1054
|
+
return {
|
|
1055
|
+
minFeeA: param.min_fee_a,
|
|
1056
|
+
minFeeB: param.min_fee_b,
|
|
1057
|
+
maxTxSize: param.max_tx_size,
|
|
1058
|
+
maxValSize: param.max_val_size,
|
|
1059
|
+
keyDeposit: param.key_deposit,
|
|
1060
|
+
poolDeposit: param.pool_deposit,
|
|
1061
|
+
priceMem: param.price_mem,
|
|
1062
|
+
priceStep: param.price_step,
|
|
1063
|
+
maxTxExMem: param.max_tx_ex_mem,
|
|
1064
|
+
maxTxExSteps: param.max_tx_ex_steps,
|
|
1065
|
+
coinsPerUtxoByte: param.coins_per_utxo_size,
|
|
1066
|
+
collateralPercentage: param.collateral_percent,
|
|
1067
|
+
maxCollateralInputs: param.max_collateral_inputs,
|
|
1068
|
+
costModels: {
|
|
1069
|
+
PlutusV1: Object.fromEntries(
|
|
1070
|
+
param.cost_models.PlutusV1.map((value, index) => [
|
|
1071
|
+
index.toString(),
|
|
1072
|
+
value
|
|
1073
|
+
])
|
|
1074
|
+
),
|
|
1075
|
+
PlutusV2: Object.fromEntries(
|
|
1076
|
+
param.cost_models.PlutusV2.map((value, index) => [
|
|
1077
|
+
index.toString(),
|
|
1078
|
+
value
|
|
1079
|
+
])
|
|
1080
|
+
)
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
async getUtxos(addressOrCredential) {
|
|
1085
|
+
if (typeof addressOrCredential === "string") {
|
|
1086
|
+
const body = {
|
|
1087
|
+
_addresses: [addressOrCredential]
|
|
1088
|
+
};
|
|
1089
|
+
const result = await fetch(`${this.baseUrl}/address_info`, {
|
|
1090
|
+
headers: {
|
|
1091
|
+
Accept: "application/json",
|
|
1092
|
+
"Content-Type": "application/json"
|
|
1093
|
+
},
|
|
1094
|
+
method: "POST",
|
|
1095
|
+
body: JSON.stringify(body)
|
|
1096
|
+
}).then((res) => res.json());
|
|
1097
|
+
const parsedResult = S2.decodeUnknownSync(KoiosAddressInfoSchema)(
|
|
1098
|
+
result
|
|
1099
|
+
)[0];
|
|
1100
|
+
return parsedResult ? parsedResult.utxo_set.map(
|
|
1101
|
+
(koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
|
|
1102
|
+
) : [];
|
|
1103
|
+
} else {
|
|
1104
|
+
throw Error("getUtxos by Credential Type is not supported in Koios yet.");
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
1108
|
+
if (typeof addressOrCredential === "string") {
|
|
1109
|
+
const utxos = await this.getUtxos(addressOrCredential);
|
|
1110
|
+
if (utxos && utxos.length > 0) {
|
|
1111
|
+
return utxos.filter((utxo) => {
|
|
1112
|
+
const keys = Object.keys(utxo.assets);
|
|
1113
|
+
return keys.length > 0 && keys.includes(unit);
|
|
1114
|
+
});
|
|
1115
|
+
} else {
|
|
1116
|
+
return [];
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
throw Error(
|
|
1120
|
+
"getUtxosWithUnit by Credential Type is not supported in Koios yet."
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
async getUtxoByUnit(unit) {
|
|
1125
|
+
let { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
|
|
1126
|
+
assetName = String(assetName);
|
|
1127
|
+
const assetAddresses = await fetch(
|
|
1128
|
+
`${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`
|
|
1129
|
+
).then((res) => res.json());
|
|
1130
|
+
if (Array.isArray(assetAddresses) && assetAddresses.length > 0) {
|
|
1131
|
+
if (assetAddresses.length > 1) {
|
|
1132
|
+
throw new Error("Unit needs to be an NFT or only held by one address.");
|
|
1133
|
+
}
|
|
1134
|
+
const utxos = await this.getUtxos(
|
|
1135
|
+
assetAddresses[0].payment_address
|
|
1136
|
+
);
|
|
1137
|
+
const result = utxos.find((utxo) => {
|
|
1138
|
+
const keys = Object.keys(utxo.assets);
|
|
1139
|
+
return keys.length > 0 && keys.includes(unit);
|
|
1140
|
+
});
|
|
1141
|
+
if (result) {
|
|
1142
|
+
return result;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
throw new Error("Unit not found.");
|
|
1146
|
+
}
|
|
1147
|
+
async getUtxosByOutRef(outRefs) {
|
|
1148
|
+
const utxos = [];
|
|
1149
|
+
const body = {
|
|
1150
|
+
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))]
|
|
1151
|
+
};
|
|
1152
|
+
const result = await fetch(`${this.baseUrl}/tx_info`, {
|
|
1153
|
+
headers: {
|
|
1154
|
+
Accept: "application/json",
|
|
1155
|
+
"Content-Type": "application/json"
|
|
1156
|
+
},
|
|
1157
|
+
method: "POST",
|
|
1158
|
+
body: JSON.stringify(body)
|
|
1159
|
+
}).then((res) => res.json());
|
|
1160
|
+
const parsedResult = S2.decodeUnknownSync(S2.Array(KoiosTxInfoSchema))(
|
|
1161
|
+
result
|
|
1162
|
+
)[0];
|
|
1163
|
+
if (parsedResult) {
|
|
1164
|
+
return parsedResult.outputs.map(
|
|
1165
|
+
(koiosInputOutput) => toUTxO(
|
|
1166
|
+
{
|
|
1167
|
+
tx_hash: koiosInputOutput.tx_hash,
|
|
1168
|
+
tx_index: koiosInputOutput.tx_index,
|
|
1169
|
+
block_height: null,
|
|
1170
|
+
value: koiosInputOutput.value,
|
|
1171
|
+
datum_hash: koiosInputOutput.datum_hash,
|
|
1172
|
+
inline_datum: koiosInputOutput.inline_datum,
|
|
1173
|
+
reference_script: koiosInputOutput.reference_script,
|
|
1174
|
+
asset_list: koiosInputOutput.asset_list
|
|
1175
|
+
},
|
|
1176
|
+
koiosInputOutput.payment_addr.bech32
|
|
1177
|
+
)
|
|
1178
|
+
);
|
|
1179
|
+
} else {
|
|
1180
|
+
return [];
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
async getDelegation(rewardAddress) {
|
|
1184
|
+
const body = {
|
|
1185
|
+
_stake_addresses: [rewardAddress]
|
|
1186
|
+
};
|
|
1187
|
+
const result = await fetch(`${this.baseUrl}/account_info`, {
|
|
1188
|
+
headers: {
|
|
1189
|
+
Accept: "application/json",
|
|
1190
|
+
"Content-Type": "application/json"
|
|
1191
|
+
},
|
|
1192
|
+
method: "POST",
|
|
1193
|
+
body: JSON.stringify(body)
|
|
1194
|
+
}).then((res) => res.json());
|
|
1195
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
1196
|
+
return {
|
|
1197
|
+
poolId: result[0].delegated_pool || null,
|
|
1198
|
+
rewards: BigInt(result[0].rewards_available)
|
|
1199
|
+
};
|
|
1200
|
+
} else {
|
|
1201
|
+
throw new Error("No Delegation Found by Reward Address");
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
async getDatum(datumHash) {
|
|
1205
|
+
const body = {
|
|
1206
|
+
_datum_hashes: [datumHash]
|
|
1207
|
+
};
|
|
1208
|
+
const datum = await fetch(`${this.baseUrl}/datum_info`, {
|
|
1209
|
+
headers: {
|
|
1210
|
+
Accept: "application/json",
|
|
1211
|
+
"Content-Type": "application/json"
|
|
1212
|
+
},
|
|
1213
|
+
method: "POST",
|
|
1214
|
+
body: JSON.stringify(body)
|
|
1215
|
+
}).then((res) => res.json());
|
|
1216
|
+
if (Array.isArray(datum) && datum.length > 0) {
|
|
1217
|
+
return datum[0].bytes;
|
|
1218
|
+
} else {
|
|
1219
|
+
throw new Error("No Datum Found by Datum Hash");
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
awaitTx(txHash, checkInterval = 3e3) {
|
|
1223
|
+
return new Promise((res) => {
|
|
1224
|
+
const confirmation = setInterval(async () => {
|
|
1225
|
+
const body = {
|
|
1226
|
+
_tx_hashes: [txHash]
|
|
1227
|
+
};
|
|
1228
|
+
const result = await fetch(`${this.baseUrl}/tx_info`, {
|
|
1229
|
+
headers: {
|
|
1230
|
+
Accept: "application/json",
|
|
1231
|
+
"Content-Type": "application/json"
|
|
1232
|
+
},
|
|
1233
|
+
method: "POST",
|
|
1234
|
+
body: JSON.stringify(body)
|
|
1235
|
+
}).then((res2) => res2.json());
|
|
1236
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
1237
|
+
clearInterval(confirmation);
|
|
1238
|
+
await new Promise((res2) => setTimeout(() => res2(1), 1e3));
|
|
1239
|
+
return res(true);
|
|
1240
|
+
}
|
|
1241
|
+
}, checkInterval);
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
async submitTx(tx) {
|
|
1245
|
+
const result = await fetch(`${this.baseUrl}/submittx`, {
|
|
1246
|
+
headers: {
|
|
1247
|
+
Accept: "application/json",
|
|
1248
|
+
"Content-Type": "application/cbor"
|
|
1249
|
+
},
|
|
1250
|
+
method: "POST",
|
|
1251
|
+
body: (0, import_core_utils3.fromHex)(tx)
|
|
1252
|
+
}).then((res) => res.json());
|
|
1253
|
+
if (!result || result.error) {
|
|
1254
|
+
if (result?.status_code === 400)
|
|
1255
|
+
throw new Error(result.message);
|
|
1256
|
+
else
|
|
1257
|
+
throw new Error("Could not submit transaction.");
|
|
1258
|
+
}
|
|
1259
|
+
return result;
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
var toUTxO = (koiosUTxO, address) => ({
|
|
1263
|
+
txHash: koiosUTxO.tx_hash,
|
|
1264
|
+
outputIndex: koiosUTxO.tx_index,
|
|
1265
|
+
assets: (() => {
|
|
1266
|
+
const a = {};
|
|
1267
|
+
koiosUTxO.asset_list.forEach((am) => {
|
|
1268
|
+
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
1269
|
+
});
|
|
1270
|
+
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
1271
|
+
return a;
|
|
1272
|
+
})(),
|
|
1273
|
+
address,
|
|
1274
|
+
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash,
|
|
1275
|
+
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
1276
|
+
scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
|
|
1277
|
+
type: "PlutusV1",
|
|
1278
|
+
script: (0, import_utils4.applyDoubleCborEncoding)(koiosUTxO.reference_script.bytes)
|
|
1279
|
+
} : {
|
|
1280
|
+
type: "PlutusV2",
|
|
1281
|
+
script: (0, import_utils4.applyDoubleCborEncoding)(koiosUTxO.reference_script.bytes)
|
|
1282
|
+
} : void 0
|
|
1283
|
+
});
|
|
846
1284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
847
1285
|
0 && (module.exports = {
|
|
848
1286
|
Blockfrost,
|
|
1287
|
+
Koios,
|
|
849
1288
|
Kupmios,
|
|
850
1289
|
Maestro,
|
|
851
1290
|
datumJsonToCbor
|
package/dist/index.d.cts
CHANGED
|
@@ -80,4 +80,21 @@ declare class Maestro implements Provider {
|
|
|
80
80
|
private getAllPagesData;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @description This class supports Koios API v1.1.2.
|
|
85
|
+
*/
|
|
86
|
+
declare class Koios implements Provider {
|
|
87
|
+
private readonly baseUrl;
|
|
88
|
+
constructor(baseUrl: string);
|
|
89
|
+
getProtocolParameters(): Promise<ProtocolParameters>;
|
|
90
|
+
getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
|
|
91
|
+
getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
|
|
92
|
+
getUtxoByUnit(unit: Unit): Promise<UTxO>;
|
|
93
|
+
getUtxosByOutRef(outRefs: OutRef[]): Promise<UTxO[]>;
|
|
94
|
+
getDelegation(rewardAddress: RewardAddress): Promise<Delegation>;
|
|
95
|
+
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
96
|
+
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
97
|
+
submitTx(tx: Transaction): Promise<TxHash>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { Blockfrost, Koios, Kupmios, Maestro, type MaestroConfig, type MaestroSupportedNetworks, datumJsonToCbor };
|
package/dist/index.d.ts
CHANGED
|
@@ -80,4 +80,21 @@ declare class Maestro implements Provider {
|
|
|
80
80
|
private getAllPagesData;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @description This class supports Koios API v1.1.2.
|
|
85
|
+
*/
|
|
86
|
+
declare class Koios implements Provider {
|
|
87
|
+
private readonly baseUrl;
|
|
88
|
+
constructor(baseUrl: string);
|
|
89
|
+
getProtocolParameters(): Promise<ProtocolParameters>;
|
|
90
|
+
getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
|
|
91
|
+
getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
|
|
92
|
+
getUtxoByUnit(unit: Unit): Promise<UTxO>;
|
|
93
|
+
getUtxosByOutRef(outRefs: OutRef[]): Promise<UTxO[]>;
|
|
94
|
+
getDelegation(rewardAddress: RewardAddress): Promise<Delegation>;
|
|
95
|
+
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
96
|
+
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
97
|
+
submitTx(tx: Transaction): Promise<TxHash>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { Blockfrost, Koios, Kupmios, Maestro, type MaestroConfig, type MaestroSupportedNetworks, datumJsonToCbor };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
|
8
8
|
// package.json
|
|
9
9
|
var package_default = {
|
|
10
10
|
name: "@lucid-evolution/provider",
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.21",
|
|
12
12
|
description: "",
|
|
13
13
|
main: "./dist/index.js",
|
|
14
14
|
types: "./dist/index.d.ts",
|
|
@@ -28,7 +28,8 @@ var package_default = {
|
|
|
28
28
|
},
|
|
29
29
|
scripts: {
|
|
30
30
|
build: "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
31
|
-
clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
31
|
+
clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
32
|
+
test: "vitest run"
|
|
32
33
|
},
|
|
33
34
|
keywords: [],
|
|
34
35
|
author: "",
|
|
@@ -37,8 +38,9 @@ var package_default = {
|
|
|
37
38
|
"@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
|
|
38
39
|
},
|
|
39
40
|
dependencies: {
|
|
40
|
-
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
41
41
|
"@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
|
|
42
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
43
|
+
"@effect/schema": "^0.67.16",
|
|
42
44
|
"@lucid-evolution/core-types": "workspace:*",
|
|
43
45
|
"@lucid-evolution/core-utils": "workspace:*",
|
|
44
46
|
"@lucid-evolution/utils": "workspace:*"
|
|
@@ -46,7 +48,8 @@ var package_default = {
|
|
|
46
48
|
devDependencies: {
|
|
47
49
|
"@types/node": "^20.12.8",
|
|
48
50
|
tsup: "^8.0.2",
|
|
49
|
-
typescript: "^5.4.5"
|
|
51
|
+
typescript: "^5.4.5",
|
|
52
|
+
vitest: "^1.6.0"
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
55
|
|
|
@@ -804,8 +807,443 @@ var Maestro = class {
|
|
|
804
807
|
}
|
|
805
808
|
};
|
|
806
809
|
var lucid2 = package_default.version;
|
|
810
|
+
|
|
811
|
+
// src/koios/koios.ts
|
|
812
|
+
import * as S2 from "@effect/schema/Schema";
|
|
813
|
+
import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
|
|
814
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding3, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
|
|
815
|
+
|
|
816
|
+
// src/koios/schema.ts
|
|
817
|
+
import * as S from "@effect/schema/Schema";
|
|
818
|
+
var ProtocolParametersSchema = S.Struct({
|
|
819
|
+
epoch_no: S.Number,
|
|
820
|
+
min_fee_a: S.Number,
|
|
821
|
+
min_fee_b: S.Number,
|
|
822
|
+
max_block_size: S.Number,
|
|
823
|
+
max_tx_size: S.Number,
|
|
824
|
+
max_bh_size: S.Number,
|
|
825
|
+
key_deposit: S.BigInt,
|
|
826
|
+
pool_deposit: S.BigInt,
|
|
827
|
+
max_epoch: S.Number,
|
|
828
|
+
optimal_pool_count: S.Number,
|
|
829
|
+
influence: S.Number,
|
|
830
|
+
monetary_expand_rate: S.Number,
|
|
831
|
+
treasury_growth_rate: S.Number,
|
|
832
|
+
decentralisation: S.Number,
|
|
833
|
+
extra_entropy: S.NullOr(S.String),
|
|
834
|
+
protocol_major: S.Number,
|
|
835
|
+
protocol_minor: S.Number,
|
|
836
|
+
min_utxo_value: S.String,
|
|
837
|
+
min_pool_cost: S.String,
|
|
838
|
+
nonce: S.String,
|
|
839
|
+
block_hash: S.NullOr(S.String),
|
|
840
|
+
cost_models: S.Struct({
|
|
841
|
+
PlutusV1: S.Array(S.Number),
|
|
842
|
+
PlutusV2: S.Array(S.Number)
|
|
843
|
+
}),
|
|
844
|
+
price_mem: S.Number,
|
|
845
|
+
price_step: S.Number,
|
|
846
|
+
max_tx_ex_mem: S.BigIntFromNumber,
|
|
847
|
+
max_tx_ex_steps: S.BigIntFromNumber,
|
|
848
|
+
max_block_ex_mem: S.Number,
|
|
849
|
+
max_block_ex_steps: S.Number,
|
|
850
|
+
max_val_size: S.Number,
|
|
851
|
+
collateral_percent: S.Number,
|
|
852
|
+
max_collateral_inputs: S.Number,
|
|
853
|
+
coins_per_utxo_size: S.BigInt
|
|
854
|
+
});
|
|
855
|
+
var KoiosAssetSchema = S.Struct({
|
|
856
|
+
policy_id: S.String,
|
|
857
|
+
asset_name: S.NullOr(S.String),
|
|
858
|
+
fingerprint: S.String,
|
|
859
|
+
decimals: S.Number,
|
|
860
|
+
quantity: S.String
|
|
861
|
+
});
|
|
862
|
+
var KoiosUTxOSchema = S.Struct({
|
|
863
|
+
tx_hash: S.String,
|
|
864
|
+
tx_index: S.Number,
|
|
865
|
+
block_height: S.NullOr(S.Number),
|
|
866
|
+
value: S.String,
|
|
867
|
+
datum_hash: S.NullOr(S.String),
|
|
868
|
+
inline_datum: S.NullOr(
|
|
869
|
+
S.Struct({
|
|
870
|
+
bytes: S.String,
|
|
871
|
+
value: S.Object
|
|
872
|
+
})
|
|
873
|
+
),
|
|
874
|
+
reference_script: S.NullOr(
|
|
875
|
+
S.Struct({
|
|
876
|
+
hash: S.String,
|
|
877
|
+
size: S.Number,
|
|
878
|
+
type: S.String,
|
|
879
|
+
bytes: S.String,
|
|
880
|
+
value: S.NullOr(S.Object)
|
|
881
|
+
})
|
|
882
|
+
),
|
|
883
|
+
asset_list: S.Array(KoiosAssetSchema)
|
|
884
|
+
});
|
|
885
|
+
var KoiosAddressInfoSchema = S.Array(
|
|
886
|
+
S.NullishOr(
|
|
887
|
+
S.Struct({
|
|
888
|
+
address: S.String,
|
|
889
|
+
balance: S.String,
|
|
890
|
+
stake_address: S.NullOr(S.String),
|
|
891
|
+
script_address: S.Boolean,
|
|
892
|
+
utxo_set: S.Array(KoiosUTxOSchema)
|
|
893
|
+
})
|
|
894
|
+
)
|
|
895
|
+
);
|
|
896
|
+
var KoiosInputOutputSchema = S.Struct({
|
|
897
|
+
payment_addr: S.Struct({
|
|
898
|
+
bech32: S.String,
|
|
899
|
+
cred: S.String
|
|
900
|
+
}),
|
|
901
|
+
stake_addr: S.NullOr(S.String),
|
|
902
|
+
tx_hash: S.String,
|
|
903
|
+
tx_index: S.Number,
|
|
904
|
+
value: S.String,
|
|
905
|
+
datum_hash: S.NullOr(S.String),
|
|
906
|
+
inline_datum: S.NullOr(
|
|
907
|
+
S.Struct({
|
|
908
|
+
bytes: S.String,
|
|
909
|
+
value: S.Object
|
|
910
|
+
})
|
|
911
|
+
),
|
|
912
|
+
reference_script: S.NullOr(
|
|
913
|
+
S.Struct({
|
|
914
|
+
hash: S.String,
|
|
915
|
+
size: S.Number,
|
|
916
|
+
type: S.String,
|
|
917
|
+
bytes: S.String,
|
|
918
|
+
value: S.NullOr(S.Object)
|
|
919
|
+
})
|
|
920
|
+
),
|
|
921
|
+
asset_list: S.Array(KoiosAssetSchema)
|
|
922
|
+
});
|
|
923
|
+
var KoiosTxInfoSchema = S.Struct({
|
|
924
|
+
tx_hash: S.String,
|
|
925
|
+
block_hash: S.String,
|
|
926
|
+
block_height: S.Number,
|
|
927
|
+
epoch_no: S.Number,
|
|
928
|
+
epoch_slot: S.Number,
|
|
929
|
+
absolute_slot: S.Number,
|
|
930
|
+
tx_timestamp: S.Number,
|
|
931
|
+
tx_block_index: S.Number,
|
|
932
|
+
tx_size: S.Number,
|
|
933
|
+
total_output: S.String,
|
|
934
|
+
fee: S.String,
|
|
935
|
+
deposit: S.String,
|
|
936
|
+
invalid_before: S.NullOr(S.String),
|
|
937
|
+
invalid_after: S.NullOr(S.String),
|
|
938
|
+
collateral_inputs: S.NullOr(S.Array(KoiosInputOutputSchema)),
|
|
939
|
+
collateral_output: S.NullOr(KoiosInputOutputSchema),
|
|
940
|
+
reference_inputs: S.NullOr(S.Array(KoiosInputOutputSchema)),
|
|
941
|
+
inputs: S.Array(KoiosInputOutputSchema),
|
|
942
|
+
outputs: S.Array(KoiosInputOutputSchema),
|
|
943
|
+
withdrawals: S.NullOr(
|
|
944
|
+
S.Array(
|
|
945
|
+
S.Struct({
|
|
946
|
+
amount: S.String,
|
|
947
|
+
stake_addr: S.String
|
|
948
|
+
})
|
|
949
|
+
)
|
|
950
|
+
),
|
|
951
|
+
assets_minted: S.NullOr(S.Array(KoiosAssetSchema)),
|
|
952
|
+
metadata: S.NullOr(S.Object),
|
|
953
|
+
certificates: S.NullOr(
|
|
954
|
+
S.Array(
|
|
955
|
+
S.Struct({
|
|
956
|
+
index: S.Number,
|
|
957
|
+
type: S.String,
|
|
958
|
+
info: S.NullOr(S.Object)
|
|
959
|
+
})
|
|
960
|
+
)
|
|
961
|
+
),
|
|
962
|
+
native_scripts: S.NullOr(
|
|
963
|
+
S.Array(
|
|
964
|
+
S.Struct({
|
|
965
|
+
script_hash: S.String,
|
|
966
|
+
script_json: S.Object
|
|
967
|
+
})
|
|
968
|
+
)
|
|
969
|
+
),
|
|
970
|
+
plutus_contracts: S.NullOr(
|
|
971
|
+
S.Array(
|
|
972
|
+
S.Struct({
|
|
973
|
+
address: S.String,
|
|
974
|
+
spends_inputs: S.NullOr(
|
|
975
|
+
S.Struct({
|
|
976
|
+
tx_hash: S.String,
|
|
977
|
+
tx_index: S.Number
|
|
978
|
+
})
|
|
979
|
+
),
|
|
980
|
+
script_hash: S.String,
|
|
981
|
+
bytecode: S.String,
|
|
982
|
+
size: S.Number,
|
|
983
|
+
valid_contract: S.Boolean,
|
|
984
|
+
input: S.Struct({
|
|
985
|
+
redeemer: S.Struct({
|
|
986
|
+
purpose: S.Literal("spend", "mint", "cert", "reward")
|
|
987
|
+
})
|
|
988
|
+
}),
|
|
989
|
+
fee: S.String,
|
|
990
|
+
unit: S.Struct({
|
|
991
|
+
steps: S.String,
|
|
992
|
+
mem: S.String
|
|
993
|
+
}),
|
|
994
|
+
datum: S.Struct({
|
|
995
|
+
hash: S.NullOr(S.String),
|
|
996
|
+
value: S.NullOr(S.Object)
|
|
997
|
+
})
|
|
998
|
+
})
|
|
999
|
+
)
|
|
1000
|
+
)
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
// src/koios/koios.ts
|
|
1004
|
+
var Koios = class {
|
|
1005
|
+
baseUrl;
|
|
1006
|
+
constructor(baseUrl) {
|
|
1007
|
+
this.baseUrl = baseUrl;
|
|
1008
|
+
}
|
|
1009
|
+
async getProtocolParameters() {
|
|
1010
|
+
const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
|
|
1011
|
+
(res) => res.json()
|
|
1012
|
+
);
|
|
1013
|
+
const param = S2.decodeUnknownSync(ProtocolParametersSchema)(result[0]);
|
|
1014
|
+
return {
|
|
1015
|
+
minFeeA: param.min_fee_a,
|
|
1016
|
+
minFeeB: param.min_fee_b,
|
|
1017
|
+
maxTxSize: param.max_tx_size,
|
|
1018
|
+
maxValSize: param.max_val_size,
|
|
1019
|
+
keyDeposit: param.key_deposit,
|
|
1020
|
+
poolDeposit: param.pool_deposit,
|
|
1021
|
+
priceMem: param.price_mem,
|
|
1022
|
+
priceStep: param.price_step,
|
|
1023
|
+
maxTxExMem: param.max_tx_ex_mem,
|
|
1024
|
+
maxTxExSteps: param.max_tx_ex_steps,
|
|
1025
|
+
coinsPerUtxoByte: param.coins_per_utxo_size,
|
|
1026
|
+
collateralPercentage: param.collateral_percent,
|
|
1027
|
+
maxCollateralInputs: param.max_collateral_inputs,
|
|
1028
|
+
costModels: {
|
|
1029
|
+
PlutusV1: Object.fromEntries(
|
|
1030
|
+
param.cost_models.PlutusV1.map((value, index) => [
|
|
1031
|
+
index.toString(),
|
|
1032
|
+
value
|
|
1033
|
+
])
|
|
1034
|
+
),
|
|
1035
|
+
PlutusV2: Object.fromEntries(
|
|
1036
|
+
param.cost_models.PlutusV2.map((value, index) => [
|
|
1037
|
+
index.toString(),
|
|
1038
|
+
value
|
|
1039
|
+
])
|
|
1040
|
+
)
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
async getUtxos(addressOrCredential) {
|
|
1045
|
+
if (typeof addressOrCredential === "string") {
|
|
1046
|
+
const body = {
|
|
1047
|
+
_addresses: [addressOrCredential]
|
|
1048
|
+
};
|
|
1049
|
+
const result = await fetch(`${this.baseUrl}/address_info`, {
|
|
1050
|
+
headers: {
|
|
1051
|
+
Accept: "application/json",
|
|
1052
|
+
"Content-Type": "application/json"
|
|
1053
|
+
},
|
|
1054
|
+
method: "POST",
|
|
1055
|
+
body: JSON.stringify(body)
|
|
1056
|
+
}).then((res) => res.json());
|
|
1057
|
+
const parsedResult = S2.decodeUnknownSync(KoiosAddressInfoSchema)(
|
|
1058
|
+
result
|
|
1059
|
+
)[0];
|
|
1060
|
+
return parsedResult ? parsedResult.utxo_set.map(
|
|
1061
|
+
(koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
|
|
1062
|
+
) : [];
|
|
1063
|
+
} else {
|
|
1064
|
+
throw Error("getUtxos by Credential Type is not supported in Koios yet.");
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
1068
|
+
if (typeof addressOrCredential === "string") {
|
|
1069
|
+
const utxos = await this.getUtxos(addressOrCredential);
|
|
1070
|
+
if (utxos && utxos.length > 0) {
|
|
1071
|
+
return utxos.filter((utxo) => {
|
|
1072
|
+
const keys = Object.keys(utxo.assets);
|
|
1073
|
+
return keys.length > 0 && keys.includes(unit);
|
|
1074
|
+
});
|
|
1075
|
+
} else {
|
|
1076
|
+
return [];
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
throw Error(
|
|
1080
|
+
"getUtxosWithUnit by Credential Type is not supported in Koios yet."
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
async getUtxoByUnit(unit) {
|
|
1085
|
+
let { policyId, assetName } = fromUnit2(unit);
|
|
1086
|
+
assetName = String(assetName);
|
|
1087
|
+
const assetAddresses = await fetch(
|
|
1088
|
+
`${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`
|
|
1089
|
+
).then((res) => res.json());
|
|
1090
|
+
if (Array.isArray(assetAddresses) && assetAddresses.length > 0) {
|
|
1091
|
+
if (assetAddresses.length > 1) {
|
|
1092
|
+
throw new Error("Unit needs to be an NFT or only held by one address.");
|
|
1093
|
+
}
|
|
1094
|
+
const utxos = await this.getUtxos(
|
|
1095
|
+
assetAddresses[0].payment_address
|
|
1096
|
+
);
|
|
1097
|
+
const result = utxos.find((utxo) => {
|
|
1098
|
+
const keys = Object.keys(utxo.assets);
|
|
1099
|
+
return keys.length > 0 && keys.includes(unit);
|
|
1100
|
+
});
|
|
1101
|
+
if (result) {
|
|
1102
|
+
return result;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
throw new Error("Unit not found.");
|
|
1106
|
+
}
|
|
1107
|
+
async getUtxosByOutRef(outRefs) {
|
|
1108
|
+
const utxos = [];
|
|
1109
|
+
const body = {
|
|
1110
|
+
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))]
|
|
1111
|
+
};
|
|
1112
|
+
const result = await fetch(`${this.baseUrl}/tx_info`, {
|
|
1113
|
+
headers: {
|
|
1114
|
+
Accept: "application/json",
|
|
1115
|
+
"Content-Type": "application/json"
|
|
1116
|
+
},
|
|
1117
|
+
method: "POST",
|
|
1118
|
+
body: JSON.stringify(body)
|
|
1119
|
+
}).then((res) => res.json());
|
|
1120
|
+
const parsedResult = S2.decodeUnknownSync(S2.Array(KoiosTxInfoSchema))(
|
|
1121
|
+
result
|
|
1122
|
+
)[0];
|
|
1123
|
+
if (parsedResult) {
|
|
1124
|
+
return parsedResult.outputs.map(
|
|
1125
|
+
(koiosInputOutput) => toUTxO(
|
|
1126
|
+
{
|
|
1127
|
+
tx_hash: koiosInputOutput.tx_hash,
|
|
1128
|
+
tx_index: koiosInputOutput.tx_index,
|
|
1129
|
+
block_height: null,
|
|
1130
|
+
value: koiosInputOutput.value,
|
|
1131
|
+
datum_hash: koiosInputOutput.datum_hash,
|
|
1132
|
+
inline_datum: koiosInputOutput.inline_datum,
|
|
1133
|
+
reference_script: koiosInputOutput.reference_script,
|
|
1134
|
+
asset_list: koiosInputOutput.asset_list
|
|
1135
|
+
},
|
|
1136
|
+
koiosInputOutput.payment_addr.bech32
|
|
1137
|
+
)
|
|
1138
|
+
);
|
|
1139
|
+
} else {
|
|
1140
|
+
return [];
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
async getDelegation(rewardAddress) {
|
|
1144
|
+
const body = {
|
|
1145
|
+
_stake_addresses: [rewardAddress]
|
|
1146
|
+
};
|
|
1147
|
+
const result = await fetch(`${this.baseUrl}/account_info`, {
|
|
1148
|
+
headers: {
|
|
1149
|
+
Accept: "application/json",
|
|
1150
|
+
"Content-Type": "application/json"
|
|
1151
|
+
},
|
|
1152
|
+
method: "POST",
|
|
1153
|
+
body: JSON.stringify(body)
|
|
1154
|
+
}).then((res) => res.json());
|
|
1155
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
1156
|
+
return {
|
|
1157
|
+
poolId: result[0].delegated_pool || null,
|
|
1158
|
+
rewards: BigInt(result[0].rewards_available)
|
|
1159
|
+
};
|
|
1160
|
+
} else {
|
|
1161
|
+
throw new Error("No Delegation Found by Reward Address");
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
async getDatum(datumHash) {
|
|
1165
|
+
const body = {
|
|
1166
|
+
_datum_hashes: [datumHash]
|
|
1167
|
+
};
|
|
1168
|
+
const datum = await fetch(`${this.baseUrl}/datum_info`, {
|
|
1169
|
+
headers: {
|
|
1170
|
+
Accept: "application/json",
|
|
1171
|
+
"Content-Type": "application/json"
|
|
1172
|
+
},
|
|
1173
|
+
method: "POST",
|
|
1174
|
+
body: JSON.stringify(body)
|
|
1175
|
+
}).then((res) => res.json());
|
|
1176
|
+
if (Array.isArray(datum) && datum.length > 0) {
|
|
1177
|
+
return datum[0].bytes;
|
|
1178
|
+
} else {
|
|
1179
|
+
throw new Error("No Datum Found by Datum Hash");
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
awaitTx(txHash, checkInterval = 3e3) {
|
|
1183
|
+
return new Promise((res) => {
|
|
1184
|
+
const confirmation = setInterval(async () => {
|
|
1185
|
+
const body = {
|
|
1186
|
+
_tx_hashes: [txHash]
|
|
1187
|
+
};
|
|
1188
|
+
const result = await fetch(`${this.baseUrl}/tx_info`, {
|
|
1189
|
+
headers: {
|
|
1190
|
+
Accept: "application/json",
|
|
1191
|
+
"Content-Type": "application/json"
|
|
1192
|
+
},
|
|
1193
|
+
method: "POST",
|
|
1194
|
+
body: JSON.stringify(body)
|
|
1195
|
+
}).then((res2) => res2.json());
|
|
1196
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
1197
|
+
clearInterval(confirmation);
|
|
1198
|
+
await new Promise((res2) => setTimeout(() => res2(1), 1e3));
|
|
1199
|
+
return res(true);
|
|
1200
|
+
}
|
|
1201
|
+
}, checkInterval);
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
async submitTx(tx) {
|
|
1205
|
+
const result = await fetch(`${this.baseUrl}/submittx`, {
|
|
1206
|
+
headers: {
|
|
1207
|
+
Accept: "application/json",
|
|
1208
|
+
"Content-Type": "application/cbor"
|
|
1209
|
+
},
|
|
1210
|
+
method: "POST",
|
|
1211
|
+
body: fromHex3(tx)
|
|
1212
|
+
}).then((res) => res.json());
|
|
1213
|
+
if (!result || result.error) {
|
|
1214
|
+
if (result?.status_code === 400)
|
|
1215
|
+
throw new Error(result.message);
|
|
1216
|
+
else
|
|
1217
|
+
throw new Error("Could not submit transaction.");
|
|
1218
|
+
}
|
|
1219
|
+
return result;
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
var toUTxO = (koiosUTxO, address) => ({
|
|
1223
|
+
txHash: koiosUTxO.tx_hash,
|
|
1224
|
+
outputIndex: koiosUTxO.tx_index,
|
|
1225
|
+
assets: (() => {
|
|
1226
|
+
const a = {};
|
|
1227
|
+
koiosUTxO.asset_list.forEach((am) => {
|
|
1228
|
+
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
1229
|
+
});
|
|
1230
|
+
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
1231
|
+
return a;
|
|
1232
|
+
})(),
|
|
1233
|
+
address,
|
|
1234
|
+
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash,
|
|
1235
|
+
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
1236
|
+
scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
|
|
1237
|
+
type: "PlutusV1",
|
|
1238
|
+
script: applyDoubleCborEncoding3(koiosUTxO.reference_script.bytes)
|
|
1239
|
+
} : {
|
|
1240
|
+
type: "PlutusV2",
|
|
1241
|
+
script: applyDoubleCborEncoding3(koiosUTxO.reference_script.bytes)
|
|
1242
|
+
} : void 0
|
|
1243
|
+
});
|
|
807
1244
|
export {
|
|
808
1245
|
Blockfrost,
|
|
1246
|
+
Koios,
|
|
809
1247
|
Kupmios,
|
|
810
1248
|
Maestro,
|
|
811
1249
|
datumJsonToCbor
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,19 +25,22 @@
|
|
|
25
25
|
"@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
29
28
|
"@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
|
|
30
|
-
"@
|
|
29
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
30
|
+
"@effect/schema": "^0.67.16",
|
|
31
31
|
"@lucid-evolution/core-utils": "0.1.6",
|
|
32
|
+
"@lucid-evolution/core-types": "0.1.6",
|
|
32
33
|
"@lucid-evolution/utils": "0.1.15"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "^20.12.8",
|
|
36
37
|
"tsup": "^8.0.2",
|
|
37
|
-
"typescript": "^5.4.5"
|
|
38
|
+
"typescript": "^5.4.5",
|
|
39
|
+
"vitest": "^1.6.0"
|
|
38
40
|
},
|
|
39
41
|
"scripts": {
|
|
40
42
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
41
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
43
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
44
|
+
"test": "vitest run"
|
|
42
45
|
}
|
|
43
46
|
}
|