Skip to content

Commit

Permalink
Merge pull request #109 from leo42/Smart-wallet-connector
Browse files Browse the repository at this point in the history
Smart wallet connector
  • Loading branch information
leo42 authored Feb 9, 2025
2 parents a14a4e4 + 41587c4 commit b63bb37
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 157 deletions.
35 changes: 26 additions & 9 deletions Fe/src/components/SmartWallet/mintingModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import contracts from "../../core/contracts.json";
import { App } from "../../index";
import { validatorToAddress } from "@lucid-evolution/utils";
import SmartWalletContainer from "./SmartWalletContainer";
import { coinSelect } from "../../core/coinSelect";



Expand Down Expand Up @@ -94,10 +95,11 @@ class MintingModule extends React.Component<MintingProps> {


async mint( wallet : string , settings : any, name: string ){

const couponId = contracts[this.props.root.state.settings.network as NetworkType].minting.couponId
function stringToChunks(string : string) {
const chunks = [];
while (string.length > 0) {

chunks.push(string.substring(0, 56));
string = string.substring(56, string.length);
}
Expand All @@ -120,21 +122,37 @@ class MintingModule extends React.Component<MintingProps> {
if (!adminUtxo) {
throw new Error("Could not fetch admin UTxO - the service might be temporarily unavailable");
}
const adminDatum = Data.from(adminUtxo?.datum as string, adminDatumSchema)

const paymentCredential = getAddressDetails(address).paymentCredential;
if (!paymentCredential) {
throw new Error("Payment credential not found");
}
const utxos = (await lucid.config().provider!.getUtxos(paymentCredential)).slice(0, 5)
console.log("utxos", utxos)
const utxos = (await lucid.config().provider!.getUtxos(paymentCredential))

const couponUtxo = utxos.find(utxo => utxo.assets[couponId] >= 1n)
console.log("utxos", utxos, couponUtxo)
const filteredUtxos = utxos.filter(utxo => utxo !== couponUtxo);
const consumingUtxos = couponUtxo
? [couponUtxo, ...coinSelect({lovelace: BigInt(15_000_000)}, filteredUtxos)]
: coinSelect({lovelace: BigInt(adminDatum.mintAmount + 15_000_000n)}, utxos);

console.log("consumingUtxos", adminDatum)
const consumingTx = lucid.newTx()
if(couponUtxo){
consumingTx.mintAssets({[couponId]: -1n}, Data.void())
consumingTx.attach.Script({ type : "PlutusV3", script : contracts[this.props.root.state.settings.network as NetworkType].minting.couponmint})
}else{
consumingTx.pay.ToAddress(contracts[this.props.root.state.settings.network as NetworkType].minting.paymentAddress, { lovelace: BigInt(adminDatum.mintAmount) });
consumingTx.readFrom([adminUtxo])
}



const policyId = mintingPolicyToId(this.mintingRawScript as MintingPolicy)
const adminDatum = Data.from(adminUtxo?.datum as string, adminDatumSchema)
const consumingTx = lucid.newTx().collectFrom(utxos)
const tokenNameSuffix = this.getTokenName(utxos[0]).slice(2);
consumingTx.pay.ToAddress(contracts[this.props.root.state.settings.network as NetworkType].minting.paymentAddress, { lovelace: BigInt(adminDatum.mintAmount) });
const tokenNameSuffix = this.getTokenName(consumingUtxos[0]).slice(2);
consumingTx.collectFrom(consumingUtxos)

const assets : Assets = {}
const assetsConfigToken : Assets = {}
const assetsRefferenceToken : Assets = {}
Expand Down Expand Up @@ -191,9 +209,8 @@ class MintingModule extends React.Component<MintingProps> {
console.log("redeemer", redeemer)

consumingTx.mintAssets(assets, redeemer)
consumingTx.attach.MintingPolicy(this.mintingRawScript as MintingPolicy)
consumingTx.attach.Script({ type: "PlutusV3", script : contracts[this.props.root.state.settings.network as NetworkType].minting.script} )
consumingTx.attachMetadata( 721 , metadata )
consumingTx.readFrom([adminUtxo])


consumingTx.pay.ToContract(configAddress, {kind : "inline" , value : initialMultisigConfig}, assetsConfigToken)
Expand Down
19 changes: 14 additions & 5 deletions Fe/src/core/contracts.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"Preprod" : {
"minting" : {
"script" : "590641010100323232323232323232322533300332323232325332330093001300b37540042646464646464a66466020646464a6666660360022a6660266016602a6ea80044c94ccc06000404c4c94cccccc0740040500500504c8c94ccc06c0040584c94cccccc08000405c05c05c05c4c94ccc074c08000c4c94ccc068c8cc004004dd61805180f1baa01722533302000114a0264a66603a64a66603c66e3cc94ccc07cc05cc084dd500089bae30253022375400226eb8c094c088dd5000980918109baa3012302137540026eb8c04cc084dd5006099b8733300e3756602660426ea8005220100488100375a602460426ea803052818118010a51133003003001302300114a2200266e1cccc024dd59807980e1baa0154891c24fc896805f0b75ab51502b022834440ef8235f134475e0c14ea935300488112546f6b656e5661756c7420566175636865720048004060dd7000980e800980e8019bad001014301a0013016375400202402402402402464a6660266008602a6ea80045300103d87a8000130193016375400264a6660266008602a6ea8004530103d87a800013006330183253330143370e9002180b1baa0011301a301737540022c6004602c6ea8c020c058dd5180c980b1baa0014bd7019198008009bac30083016375401e44a6660300022980103d87a80001323253330163371090001998031bab300b30193754601660326ea800922011c592fb0f9d8ed15c06858118d134d5c4b7c77320507810fee9ac2ddf90048810e736d6172744d696e7441646d696e00130093301b0024bd70099802002000980e001180d0009180c180c980c80091119299980a1802980b1baa0011480004dd6980d180b9baa001325333014300530163754002298103d87a8000132330010013756603660306ea8008894ccc068004530103d87a8000132323232533301a337220100042a66603466e3c0200084c034cc07cdd4000a5eb80530103d87a8000133006006003375a60380066eb8c068008c078008c070004cc01400c0084c8c94ccc048c8cc004004cc00c00cc94ccc050c014c058dd50008a5eb7bdb1804dd5980d180b9baa0013300537566012602c6ea803c028894ccc060004528899299980a99180399198008009bac300b301a375402644a6660380022900009991299980d19b8f33009372466e2cdd69807980e9baa300e301d37540046eb8c038c074dd51807180e9baa002480080144cdc0000a40042002603c00266004004603e002660086eb8c06c009200213300300300114a06036002264660020026eb0c01cc058dd500791299980c0008a511325333015337106eb4c028c060dd51804980c1baa301b002483f80c4cc00c00c004528180d8008a502233371800266e04dc680100080111299980b0008a5eb804cc05cc050c060004cc008008c064004dc3a4004294088c8cc00400400c894ccc0580045300103d87a800013232323253330163372200e0042a66602c66e3c01c0084c024cc06cdd3000a5eb80530103d87a8000133006006003375660300066eb8c058008c068008c060004dd2a4000460260024602460260024602260246024602460240026eb8c03cc030dd50011b874800058c034c038008c030004c030008c028004c018dd50008a4c2a6600892011856616c696461746f722072657475726e65642066616c7365001365615330024901ff6578706563742061646d696e446174613a2041646d696e446174756d20203d206f7074696f6e2e6f725f656c7365286f7074696f6e2e6d61702861646d696e5574786f2c20666e287574786f29207b0a2020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207768656e20287574786f2e6f75747075742e646174756d29206973207b0a202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020496e6c696e65446174756d28646261746129202d3e20646174610a2020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020205f202d3e206661696c7d7d292c204e6f6e652900165734ae7155ceaab9e5573eae815d0aba257481",
"script" : "590451010100323232323232322533300232323232325332330083001300937540042646464646464a6646601e646464a66602464a666026601860286ea80044c94ccc050cdc3a4008602a6ea80044c94ccc054c038c058dd5000899191919299980e180f801099198008009bac300a301c375402c44a66603c00229404cc894ccc0754ccc074cdc799299980f180b980f9baa0011375c604660406ea80044dd7181198101baa0013012301f37546024603e6ea8008dd71809980f9baa00913370e66601c6eacc04cc07cdd500124500488100375a6024603e6ea80245280a511330040040013020001302100116375c603a002603a0046eb4c06c004c05cdd50008b180c980b1baa00114a06006602a6ea8c024c054dd5180c180a9baa00114a064660020026eb0c024c054dd500791299980b8008a6103d87a80001332253330163371090001998039bab300c30183754601860306ea800922011c592fb0f9d8ed15c06858118d134d5c4b7c77320507810fee9ac2ddf90048810e736d6172744d696e7441646d696e001300a3301a0024bd70099802002000980c800980d0008a5110013370e6660046eacc020c04cdd5006a451c36e94375d61ea1bf95ebb1222c84b043695c56c34f980eb9c060dd6d00488112546f6b656e5661756c74205661756368657200480048c058c05cc05c004888c94ccc04cc014c050dd50008a400026eb4c060c054dd50009929998099802980a1baa00114c103d87a80001323300100137566032602c6ea8008894ccc060004530103d87a80001323332225333019337220100062a66603266e3c02000c4c034cc074dd400125eb80530103d87a8000133006006001375c602e0026eb4c060004c070008c068004cc01400c0084c8c94ccc044c8cc004004cc00c00cc94ccc04cc014c050dd50008a5eb7bdb1804dd5980c180a9baa001330053756601260286ea8038028894ccc05800452889991299980a99180419198008009bac300c3019375402644a6660360022900009991299980d19b8f3300a372466e2cdd69808180e1baa300f301c37540046eb8c03cc070dd51807980e1baa002480080144cdc0000a40042002603a00266004004603c0026600a00490010998020020008a50375c60300026032002264660020026eb0c01cc050dd500711299980b0008a51133225333015337106eb4c02cc05cdd51805180b9baa002483f80c4cc010010004528180c000980c8008a502233371800266e04dc680100080111299980a0008a5eb804cc054c048c058004cc008008c05c004dc3a4004294088c8cc00400400c894ccc0500045300103d87a800013233322253330153372200e0062a66602a66e3c01c00c4c024cc064dd300125eb80530103d87a8000133006006001375c60260026eacc050004c060008c058004dd2a4000460220024602060220024601e60206020602060200026eb8c034c028dd50011b874800058c02cc03000cc028008c024008c024004c010dd50008a4c26cacae6955ceaab9e5573eae815d0aba21",
"adminKey" : "592fb0f9d8ed15c06858118d134d5c4b7c77320507810fee9ac2ddf9736d6172744d696e7441646d696e",
"paymentAddress" : "addr_test1qpw97ty053xuqnqg0tsu3qeu5w2c8emu9lufyt24h68k6pcuf8fd97xmztpdh8l5fackuzf5r26m74p7gd924y6yecvs5f968f"
"paymentAddress" : "addr_test1qpw97ty053xuqnqg0tsu3qeu5w2c8emu9lufyt24h68k6pcuf8fd97xmztpdh8l5fackuzf5r26m74p7gd924y6yecvs5f968f",
"couponmint" : "5902350101003232323232323225333002323232323253330073370e900018041baa0011323232533300a323300100137586020601a6ea801c894ccc03c0045280999129998071803192999807980398081baa0011480004dd6980a18089baa00132533300f300730103754002298103d87a8000132330010013756602a60246ea8008894ccc050004530103d87a8000132333222533301533722911076164736166617700003153330153371e910107616473616661770000313374a90001980c9ba80024bd700a6103d87a8000133006006001375c60260026eb4c050004c060008c058004cc01cdd599180098089baa30013011375400646028602a0029111c592fb0f9d8ed15c06858118d134d5c4b7c77320507810fee9ac2ddf90014a22660080080026022002602400229444004c8cc004004c8cc004004c94ccc030c010c034dd50008a5eb7bdb1804dd5980898071baa00133004375660206022602260226022601a6ea801cdd7180818069baa00522533300f00114bd70099808180718088009980100118090009129998070008a5113322533300d3371000490000998020020008a50375a602000260220026e1d200222323300100100322533300e00114c0103d87a8000132333222533300f3372200e0062a66601e66e3c01c00c4cdd2a4000660266e980092f5c02980103d87a8000133006006001375c601a0026eacc038004c048008c04000458c02cc03000cc028008c024008c024004c010dd50008a4c26cacae6955ceaab9e5573eae815d0aba201",
"couponId" : "36e94375d61ea1bf95ebb1222c84b043695c56c34f980eb9c060dd6d546f6b656e5661756c742056617563686572"
},
"wallet" : "590673010100323232323232323223225333004323232323232332323232323232322323300100132533301530063016375400226034602e6ea800458ccc00d2211c79dfc51ebff0b40e596e6ce59a0e3306038c7214afd40f9bf1f15cd1003371690000090011119299980b180380089919198008009bac301d301e301e301e301e301e301e301e301e301a375400c44a66603800229404cc894ccc06ccdc78010028a51133004004001375c603c002603e0026eb8c06cc060dd50010a99980b18060008991991299980c99198008009bac3011301c375401044a66603c00229404cc894ccc074cdc4a40046660226eacc040c07cdd51808180f9baa00200600514a22660080080026040002604200229444c94ccc068c02cc06cdd5000899803803980f980e1baa00114a066601000400200e6eb8c070004dd7180e180e800980c1baa002153330163006001132337126eb4c070c074004c8cc004004dd6180e80111299980e0008a400026644a66603666010010004266e0000520021001301e00133002002301f001301837540042a66602c66e1d200600113232325333019300f301a3754002264a666034602060366ea8c034c070dd51806980e1baa003133710002008266e24004010dd6980f180d9baa00114a0601e60346ea8c02cc068dd50009804980c9baa005375a603660306ea800854ccc058cdc3a40100022646464a666032601e60346ea80044c94ccc068c040c06cdd51806980e1baa3011301c3754006266e200100044cdc48020009bad301e301b37540022940c03cc068dd51807980d1baa00130093019375400a6eb4c06cc060dd500109991191980080080191299980e8008a5013322533301c3375e00a00429444cc010010004c06cc07c004c080004dd5980d980e180e180e180e180e180e180c1baa0043374a90011980d180d980c1baa0024bd70180b1baa001222325333015300b30163754002298103d87a8000132533301630063017375400226464a66666603e0042646660020020062601c6603a00697ae022232533301c300d0011325333020001006132533333302500100700700700713253330223025003005008375c0026044002603c6ea800c54ccc070c0480044c94ccc0800040184c94cccccc09400401c01c01c01c4c8c94ccc08c0040244c94cccccc0a00040280280280284c94ccc094c0a000c02002cdd7000981280098128019bae0013022001301e37540062a6660386018002264a66604000200c264a66666604a00200e00e26464a666046002012264a666666050002014014014264a66604a60500062646600200200a4464a666050004016264a66666605a002266601c01c00226004605800601e01e01e01e605400460040040166eb4004028c094004c09400cdd60008038039811000980f1baa0031533301c3370e900300089929998100008030992999999812800803803803899299981118128018028041bad0010073022001301e37540062a66603866e1d20080011325333020001006132533333302500100700700713253330223025003005008375a00200e6044002603c6ea800c54ccc070cdc3a4014002264a66604000200c264a66666604a00200e00e00e00e264a666044604a00600a0106eb8004c088004c078dd5001802980e1baa00200100100100114c0103d87a8000301b301837540022980103d87a8000301a301b301b301737546010602e6ea8c068c05cdd500099198008009bac30083017375400444a6660320022980103d87a80001332253330183371090001998061bab300b301a3754601660346ea800801c0184c034cc0700092f5c0266008008002603600260380026e1d2004370e90001180a180a980a980a980a980a980a980a80091809980a000911192999808180318089baa0011480004dd6980a98091baa001325333010300630113754002298103d87a8000132330010013756602c60266ea8008894ccc054004530103d87a80001323332225333016337220100062a66602c66e3c02000c4c02ccc068dd400125eb80530103d87a8000133006006001375c60280026eb4c054004c064008c05c004c8cc004004010894ccc0500045300103d87a80001323332225333015337220100062a66602a66e3c02000c4c028cc064dd300125eb80530103d87a8000133006006001375c60260026eacc050004c060008c058004dd2a40006e1d20023001300c375400e4601e002601a601c006601800460160046016002600c6ea800452613656375c002ae6955ceaab9e5573eae815d0aba25749",
"configHost" : "590801010100323232323232323225333002323232323253323300830013009375400426466446464646464646464646464a66602ca66602c600a602e6ea80304c8c8c8cc004004c078c06cdd50079119299980d980500089919198008009bac302230233023302330233023302330233023301f375403244a66604200229404cc894ccc080cdc78010028a51133004004001375c604600260480026eb8c080c074dd50010a99980d980a0008991991299980f19198008009bac30103021375403644a66604600229404cc894ccc088cdc4a40046660186eacc05cc090dd5180b98121baa00200600514a2266008008002604a002604c00229444c94ccc07cc038c080dd5000899803803981218109baa00114a064a66603e603060406ea8004530103d87a80001325333020300e3021375400226464a6666660520042646660020020062602e6604e00697ae02223253330263015001132533302a001006132533333302f001007007007007132533302c302f003005008375c002605800260506ea800c54ccc098c07c0044c94ccc0a80040184c94cccccc0bc00401c01c01c01c4c8c94ccc0b40040244c94cccccc0c80040280280280284c94ccc0bcc0c800c02002cdd7000981780098178019bae001302c001302837540062a66604c6028002264a66605400200c264a66666605e00200e00e26464a66605a002012264a666666064002014014014264a66605e606400626603800844a666062004014264a66666606c002266601a01a00226004606a00601c01c01c01c60660040166eb4004028c0bc004c0bc00cdd6000803803981600098141baa003153330263013001132533302a001006132533333302f001007007007132533302c302f003005008375a00200e605800260506ea800c54ccc098c0480044c94ccc0a80040184c94cccccc0bc00401c01c01c4c94ccc0b0c0bc00c014020dd6800803981600098141baa003153330263370e900500089929998150008030992999999817800803803803803899299981618178018028041bae001302c0013028375400600a604c6ea80080040040040045300103d87a80003025302237540022980103d87a8000301130213754602860426ea8c090c084dd5000998089bac301330203754034466e2120003330093756602860426ea8c050c084dd50008018011bae3021001375c60426044002603a6ea800854ccc06cc0240044c8cdc49bad3021302200132330010013758604400444a6660420022900009991299981019804004001099b80001480084004c08c004cc008008c090004c074dd50010a99980d98040008991919299980f180b980f9baa001132533301f301830203754602860426ea8c050c084dd5001899b880010041337120020086eb4c08cc080dd50008a50300e301f37546024603e6ea8004c014c078dd500c1bad3020301d37540042a666036600e0022646464a66603c602e603e6ea80044c94ccc07cc060c080dd5180a18109baa301030213754006266e200100044cdc48020009bad3023302037540022940c038c07cdd51807180f9baa0013005301e37540306eb4c080c074dd50010999119198008008019129998110008a501332253330213375e00a00429444cc010010004c080c090004c094004dd59810181098109810981098109810980e9baa0173374a90011980f9810180e9baa0024bd70180d9baa0012301d301e301e301e301e301e301e301e00122232533301a3013301b37540022900009bad301f301c375400264a666034602660366ea8004530103d87a80001323300100137566040603a6ea8008894ccc07c004530103d87a80001323332225333020337220100062a66604066e3c02000c4c050cc090dd400125eb80530103d87a8000133006006001375c603c0026eb4c07c004c08c008c084004c8cc004004010894ccc0780045300103d87a8000132333222533301f337220100062a66603e66e3c02000c4c04ccc08cdd300125eb80530103d87a8000133006006001375c603a0026eacc078004c088008c080004584004528191919299980c1803980c9baa00113232533301a3009301b375400226464a6660386014603a6ea80044cc018c084c078dd5000899baf300d301e37546022603c6ea8010c034c078dd50010b1806980e9baa001301f301c37540022c660186eb0c02cc06cdd500a919baf300f301c3754002601e60386ea8c03cc070dd5001180e980d1baa001163300a3758601060326ea804c8cdd79804980d1baa00100f3001001222325333019300800113232533301e302100200416375c603e00260366ea800c54ccc064c0480044c8c8c8c94ccc080c08c00801858dd7181080098108011bae301f001301b37540062a666032600e002264646464a666040604600426601a00644a6660440040102666014014604800426002604a0042c6eb4c084004c084008dd6180f800980d9baa00315333019300600113232533301e302100200416375a603e00260366ea800c54ccc064c0140044c8c94ccc078c08400801058dd6980f800980d9baa003153330193370e900500089919299980f18108010020b1bae301f001301b37540062c60326ea8008dc3a40106e1d2006370e90021b874800088c8cc00400400c88cc00c004c0080088c0540048c050c054c05400488c8cc00400400c894ccc050004530103d87a8000133225333013300500213007330170024bd70099802002000980b000980b8009ba5480008c044c048004c038004c038c03c004c028dd50011b874800858c02cc03000cc028008c024008c024004c010dd50008a4c26cacae6955ceaab9e5573eae815d0aba257481",
Expand All @@ -15,19 +17,24 @@
"minting" : {
"script" : "script-hash-here",
"adminKey" : "admin-key-here",
"paymentAddress" : ""
"paymentAddress" : "",
"couponmint" : "",
"couponId" : ""
},
"wallet" : "script-hash-here",
"configHost" : "",
"registrationCost" :0 ,
"txFee" : 0,
"configUtxo" : 0

},
"Mainnet" : {
"minting" : {
"script" : "script-hash-here",
"adminKey" : "admin-key-here",
"paymentAddress" : ""
"paymentAddress" : "",
"couponmint" : "",
"couponId" : ""
},
"wallet" : "script-hash-here",
"configHost" : "",
Expand All @@ -39,7 +46,9 @@
"minting" : {
"script" : "script-hash-here",
"adminKey" : "admin-key-here",
"paymentAddress" : ""
"paymentAddress" : "",
"couponmint" : "",
"couponId" : ""
},
"wallet" : "script-hash-here",
"configHost" : "",
Expand Down
4 changes: 2 additions & 2 deletions Fe/src/helpers/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Messaging {

// this.port = chrome.runtime.connect("jfjmokidpopgdhcilhkoanmjcimijgng"); // Selfbuild ID
try{
// this.port = chrome.runtime.connect("mdnadibcilebgfdkadlhegdpgpglljmn"); //playstore ID
this.port = chrome.runtime.connect("emfmflhcajhodbjgkmemdncoangplkdn"); //playstore ID
this.port = chrome.runtime.connect("mdnadibcilebgfdkadlhegdpgpglljmn"); //playstore ID
// this.port = chrome.runtime.connect("emfmflhcajhodbjgkmemdncoangplkdn"); //playstore ID
}catch(e){
console.log(e)
return
Expand Down
Loading

0 comments on commit b63bb37

Please sign in to comment.