New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@anastasia-labs/linear-vesting-offchain

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anastasia-labs/linear-vesting-offchain - npm Package Compare versions

Comparing version 0.0.10 to 1.0.0

2

./dist/index.js

@@ -1,1 +0,1 @@

import{Data as A,toUnit as Y}from"@anastasia-labs/lucid-cardano-fork";import{applyDoubleCborEncoding as B,Constr as d,Data as N,generateSeedPhrase as M,getAddressDetails as E,Lucid as U}from"@anastasia-labs/lucid-cardano-fork";var K=async(t,e,n)=>{let a={type:"PlutusV2",script:e},o=n?t.utils.validatorToAddress(a,t.utils.keyHashToCredential(n)):t.utils.validatorToAddress(a);return t.utxosAt(o)},x=(t,e,n)=>{if(e)try{return{type:"right",value:N.from(e,n)}}catch(a){return{type:"left",value:`invalid datum : ${a}`}}else return{type:"left",value:"missing datum"}},w=async(t,e,n,a)=>(await K(t,e,a)).flatMap(s=>{let i=x(t,s.datum,n);return i.type=="right"?{outRef:{txHash:s.txHash,outputIndex:s.outputIndex},datum:i.value,assets:s.assets}:[]}),ee=t=>B(t),te=async t=>{let e=M();return{seedPhrase:e,address:await(await U.new(void 0,"Custom")).selectWalletFromSeed(e).wallet.address(),assets:t}};function V(t){let{paymentCredential:e,stakeCredential:n}=E(t);if(!e)throw new Error("Not a valid payment address.");return{paymentCredential:e?.type==="Key"?{PublicKeyCredential:[e.hash]}:{ScriptCredential:[e.hash]},stakeCredential:n?{Inline:[n.type==="Key"?{PublicKeyCredential:[n.hash]}:{ScriptCredential:[n.hash]}]}:null}}function g(t,e){let n=(()=>"PublicKeyCredential"in t.paymentCredential?e.utils.keyHashToCredential(t.paymentCredential.PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.paymentCredential.ScriptCredential[0]))(),a=(()=>{if(t.stakeCredential&&"Inline"in t.stakeCredential)return"PublicKeyCredential"in t.stakeCredential.Inline[0]?e.utils.keyHashToCredential(t.stakeCredential.Inline[0].PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.stakeCredential.Inline[0].ScriptCredential[0])})();return e.utils.credentialToAddress(n,a)}var re=t=>{let e=E(t);if(!e.paymentCredential)return{type:"error",error:new Error("undefined paymentCredential")};let n=e.paymentCredential.type=="Key"?new d(0,[e.paymentCredential.hash]):new d(1,[e.paymentCredential.hash]);if(!e.stakeCredential)return{type:"ok",data:new d(0,[n,new d(1,[])])};let a=new d(0,[new d(0,[new d(0,[e.stakeCredential.hash])])]);return{type:"ok",data:new d(0,[n,a])}},ne=(t,e)=>{let n=Math.ceil(t.length/e);return[...Array(n)].map((a,o)=>t.slice(o*e,(o+1)*e))},se=(t,e)=>typeof e=="bigint"?e.toString():e,p=(t,e)=>1n+(t-1n)/e;import{Data as r}from"@anastasia-labs/lucid-cardano-fork";var H=r.Object({txHash:r.Object({hash:r.Bytes({minLength:32,maxLength:32})}),outputIndex:r.Integer()}),ie=H,C=r.Enum([r.Object({PublicKeyCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])}),r.Object({ScriptCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])})]),le=C,D=r.Object({paymentCredential:C,stakeCredential:r.Nullable(r.Enum([r.Object({Inline:r.Tuple([C])}),r.Object({Pointer:r.Tuple([r.Object({slotNumber:r.Integer(),transactionIndex:r.Integer(),certificateIndex:r.Integer()})])})]))}),de=D,P=r.Object({symbol:r.Bytes(),name:r.Bytes()},{hasConstr:!1}),pe=P,F=r.Map(r.Bytes(),r.Map(r.Bytes(),r.Bytes())),ue=F,Q=r.Object({beneficiary:D,assetClass:P,totalVestingQty:r.Integer(),vestingPeriodStart:r.Integer(),vestingPeriodEnd:r.Integer(),firstUnlockPossibleAfter:r.Integer(),totalInstallments:r.Integer(),vestingMemo:r.Bytes()}),u=Q,j=r.Enum([r.Literal("PartialUnlock"),r.Literal("FullUnlock")]),T=j;var Ae=async(t,e)=>{e.currentTime??=Date.now();let n={type:"PlutusV2",script:e.scripts.vesting},a=t.utils.validatorToAddress(n),o=(await t.utxosByOutRef([e.vestingOutRef]))[0];if(!o)return{type:"error",error:new Error("No Utxo in Script")};if(!o.datum)return{type:"error",error:new Error("Missing Datum")};let s=x(t,o.datum,u);if(s.type=="left")return{type:"error",error:new Error(s.value)};let i=s.value.vestingPeriodEnd-s.value.vestingPeriodStart,l=s.value.vestingPeriodEnd-BigInt(e.currentTime),_=p(i,s.value.totalInstallments),L=p(l,_),S=p(L*s.value.totalVestingQty,s.value.totalInstallments),m=s.value.assetClass.symbol?Y(s.value.assetClass.symbol,s.value.assetClass.name):"lovelace",O=l<0n?o.assets[m]:o.assets[m]-S,y=g(s.value.beneficiary,t),v=l<0n?A.to("FullUnlock",T):A.to("PartialUnlock",T),b=Number(e.currentTime+h),k=Number(e.currentTime-h);try{return l<0n?{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[m]:O}).addSigner(y).validFrom(k).validTo(b).complete()}:{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[m]:O}).payToContract(a,{inline:A.to(s.value,u)},{[m]:S}).addSigner(y).validFrom(k).validTo(b).complete()}}catch(c){return c instanceof Error?{type:"error",error:c}:{type:"error",error:new Error(`${JSON.stringify(c)}`)}}};import{Data as W,fromText as $,toUnit as J}from"@anastasia-labs/lucid-cardano-fork";var Ve=async(t,e)=>{let n=await t.wallet.getUtxos();if(!n.length)return{type:"error",error:new Error("No utxos in wallet")};let a={type:"PlutusV2",script:e.scripts.vesting},o=t.utils.validatorToAddress(a),s=W.to({beneficiary:V(e.beneficiary),assetClass:{symbol:e.vestingAsset.policyId,name:e.vestingAsset.tokenName},totalVestingQty:BigInt(e.totalVestingQty-e.totalVestingQty*.05),vestingPeriodStart:BigInt(e.vestingPeriodStart),vestingPeriodEnd:BigInt(e.vestingPeriodEnd),firstUnlockPossibleAfter:BigInt(e.firstUnlockPossibleAfter),totalInstallments:BigInt(e.totalInstallments),vestingMemo:$(e.vestingMemo)},u),i=e.vestingAsset.policyId?J(e.vestingAsset.policyId,e.vestingAsset.tokenName):"lovelace";try{return{type:"ok",data:await t.newTx().collectFrom(n).payToContract(o,{inline:s},{[i]:BigInt(e.totalVestingQty-e.totalVestingQty*.05)}).payToAddress(t.utils.credentialToAddress(t.utils.keyHashToCredential(I),t.utils.keyHashToCredential(R)),{[i]:BigInt(e.totalVestingQty*.05)}).complete()}}catch(l){return l instanceof Error?{type:"error",error:l}:{type:"error",error:new Error(`${JSON.stringify(l)}`)}}};var _e=36e5,Le=315576e5,Be=631152e5,Ne=864e5,f=.05,h=process.env.NODE_ENV=="emulator"?0:1e5,I="014e9d57e1623f7eeef5d0a8d4e6734a562ba32cf910244cd74e1680",R="5e8aa3f089868eaadf188426f49db6566624844b6c5d529b38f3b8a7";import{toUnit as X}from"@anastasia-labs/lucid-cardano-fork";function je(t){let e=t.datum.vestingPeriodEnd-t.datum.vestingPeriodStart,n=t.datum.vestingPeriodEnd-BigInt(Date.now()),a=p(e,t.datum.totalInstallments),o=p(n,a),s=p(o*t.datum.totalVestingQty,t.datum.totalInstallments),i=t.datum.assetClass.symbol?X(t.datum.assetClass.symbol,t.datum.assetClass.name):"lovelace";return n>0n?t.assets[i]>s:!0}async function Ye(t,e,n){return(await w(t,n,u)).filter(s=>g(s.datum.beneficiary,t)==e)}export*from"@anastasia-labs/lucid-cardano-fork";export{de as AddressD,D as AddressSchema,pe as AssetClassD,P as AssetClassSchema,le as CredentialD,C as CredentialSchema,_e as ONE_HOUR_MS,Le as ONE_YEAR_MS,ie as OutputReference,H as OutputReferenceSchema,f as PROTOCOL_FEE,I as PROTOCOL_PAYMENT_KEY,R as PROTOCOL_STAKE_KEY,h as TIME_TOLERANCE_MS,Ne as TWENTY_FOUR_HOURS_MS,Be as TWO_YEARS_MS,ue as Value,F as ValueSchema,u as VestingDatum,Q as VestingDatumSchema,T as VestingRedeemer,j as VestingRedeemerSchema,je as checkVestingUtxo,ne as chunkArray,Ae as collectVestingTokens,p as divCeil,V as fromAddress,re as fromAddressToData,te as generateAccountSeedPhrase,Ye as getVestingByAddress,Ve as lockTokens,x as parseSafeDatum,w as parseUTxOsAtScript,se as replacer,g as toAddress,ee as toCBORHex,K as utxosAtScript};
import{Data as A,toUnit as Y}from"@anastasia-labs/lucid-cardano-fork";import{applyDoubleCborEncoding as B,Constr as d,Data as N,generateSeedPhrase as U,getAddressDetails as E,Lucid as M}from"@anastasia-labs/lucid-cardano-fork";var K=async(t,e,n)=>{let a={type:"PlutusV2",script:e},o=n?t.utils.validatorToAddress(a,t.utils.keyHashToCredential(n)):t.utils.validatorToAddress(a);return t.utxosAt(o)},C=(t,e,n)=>{if(e)try{return{type:"right",value:N.from(e,n)}}catch(a){return{type:"left",value:`invalid datum : ${a}`}}else return{type:"left",value:"missing datum"}},w=async(t,e,n,a)=>(await K(t,e,a)).flatMap(s=>{let i=C(t,s.datum,n);return i.type=="right"?{outRef:{txHash:s.txHash,outputIndex:s.outputIndex},datum:i.value,assets:s.assets}:[]}),z=t=>B(t),ee=async t=>{let e=U();return{seedPhrase:e,address:await(await M.new(void 0,"Custom")).selectWalletFromSeed(e).wallet.address(),assets:t}};function V(t){let{paymentCredential:e,stakeCredential:n}=E(t);if(!e)throw new Error("Not a valid payment address.");return{paymentCredential:e?.type==="Key"?{PublicKeyCredential:[e.hash]}:{ScriptCredential:[e.hash]},stakeCredential:n?{Inline:[n.type==="Key"?{PublicKeyCredential:[n.hash]}:{ScriptCredential:[n.hash]}]}:null}}function g(t,e){let n=(()=>"PublicKeyCredential"in t.paymentCredential?e.utils.keyHashToCredential(t.paymentCredential.PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.paymentCredential.ScriptCredential[0]))(),a=(()=>{if(t.stakeCredential&&"Inline"in t.stakeCredential)return"PublicKeyCredential"in t.stakeCredential.Inline[0]?e.utils.keyHashToCredential(t.stakeCredential.Inline[0].PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.stakeCredential.Inline[0].ScriptCredential[0])})();return e.utils.credentialToAddress(n,a)}var te=t=>{let e=E(t);if(!e.paymentCredential)return{type:"error",error:new Error("undefined paymentCredential")};let n=e.paymentCredential.type=="Key"?new d(0,[e.paymentCredential.hash]):new d(1,[e.paymentCredential.hash]);if(!e.stakeCredential)return{type:"ok",data:new d(0,[n,new d(1,[])])};let a=new d(0,[new d(0,[new d(0,[e.stakeCredential.hash])])]);return{type:"ok",data:new d(0,[n,a])}},re=(t,e)=>{let n=Math.ceil(t.length/e);return[...Array(n)].map((a,o)=>t.slice(o*e,(o+1)*e))},ne=(t,e)=>typeof e=="bigint"?e.toString():e,p=(t,e)=>1n+(t-1n)/e;import{Data as r}from"@anastasia-labs/lucid-cardano-fork";var H=r.Object({txHash:r.Object({hash:r.Bytes({minLength:32,maxLength:32})}),outputIndex:r.Integer()}),oe=H,x=r.Enum([r.Object({PublicKeyCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])}),r.Object({ScriptCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])})]),ie=x,D=r.Object({paymentCredential:x,stakeCredential:r.Nullable(r.Enum([r.Object({Inline:r.Tuple([x])}),r.Object({Pointer:r.Tuple([r.Object({slotNumber:r.Integer(),transactionIndex:r.Integer(),certificateIndex:r.Integer()})])})]))}),le=D,P=r.Object({symbol:r.Bytes(),name:r.Bytes()},{hasConstr:!1}),de=P,F=r.Map(r.Bytes(),r.Map(r.Bytes(),r.Bytes())),pe=F,Q=r.Object({beneficiary:D,assetClass:P,totalVestingQty:r.Integer(),vestingPeriodStart:r.Integer(),vestingPeriodEnd:r.Integer(),firstUnlockPossibleAfter:r.Integer(),totalInstallments:r.Integer()}),u=Q,j=r.Enum([r.Literal("PartialUnlock"),r.Literal("FullUnlock")]),T=j;var Te=async(t,e)=>{e.currentTime??=Date.now();let n={type:"PlutusV2",script:e.scripts.vesting},a=t.utils.validatorToAddress(n),o=(await t.utxosByOutRef([e.vestingOutRef]))[0];if(!o)return{type:"error",error:new Error("No Utxo in Script")};if(!o.datum)return{type:"error",error:new Error("Missing Datum")};let s=C(t,o.datum,u);if(s.type=="left")return{type:"error",error:new Error(s.value)};let i=s.value.vestingPeriodEnd-s.value.vestingPeriodStart,l=s.value.vestingPeriodEnd-BigInt(e.currentTime),_=p(i,s.value.totalInstallments),L=p(l,_),S=p(L*s.value.totalVestingQty,s.value.totalInstallments),c=s.value.assetClass.symbol?Y(s.value.assetClass.symbol,s.value.assetClass.name):"lovelace",O=l<0n?o.assets[c]:o.assets[c]-S,y=g(s.value.beneficiary,t),v=l<0n?A.to("FullUnlock",T):A.to("PartialUnlock",T),b=Number(e.currentTime+h),k=Number(e.currentTime-h);try{return l<0n?{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[c]:O}).addSigner(y).validFrom(k).validTo(b).complete()}:{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[c]:O}).payToContract(a,{inline:A.to(s.value,u)},{[c]:S}).addSigner(y).validFrom(k).validTo(b).complete()}}catch(m){return m instanceof Error?{type:"error",error:m}:{type:"error",error:new Error(`${JSON.stringify(m)}`)}}};import{Data as W,toUnit as $}from"@anastasia-labs/lucid-cardano-fork";var we=async(t,e)=>{let n=await t.wallet.getUtxos();if(!n.length)return{type:"error",error:new Error("No utxos in wallet")};let a={type:"PlutusV2",script:e.scripts.vesting},o=t.utils.validatorToAddress(a),s=W.to({beneficiary:V(e.beneficiary),assetClass:{symbol:e.vestingAsset.policyId,name:e.vestingAsset.tokenName},totalVestingQty:BigInt(e.totalVestingQty-e.totalVestingQty*.01),vestingPeriodStart:BigInt(e.vestingPeriodStart),vestingPeriodEnd:BigInt(e.vestingPeriodEnd),firstUnlockPossibleAfter:BigInt(e.firstUnlockPossibleAfter),totalInstallments:BigInt(e.totalInstallments)},u),i=e.vestingAsset.policyId?$(e.vestingAsset.policyId,e.vestingAsset.tokenName):"lovelace";try{return{type:"ok",data:await t.newTx().collectFrom(n).payToContract(o,{inline:s},{[i]:BigInt(e.totalVestingQty-e.totalVestingQty*.01)}).payToAddress(t.utils.credentialToAddress(t.utils.keyHashToCredential(I),t.utils.keyHashToCredential(R)),{[i]:BigInt(e.totalVestingQty*.01)}).complete()}}catch(l){return l instanceof Error?{type:"error",error:l}:{type:"error",error:new Error(`${JSON.stringify(l)}`)}}};var Re=36e5,_e=315576e5,Le=631152e5,Be=864e5,f=.01,h=process.env.NODE_ENV=="emulator"?0:1e5,I="014e9d57e1623f7eeef5d0a8d4e6734a562ba32cf910244cd74e1680",R="5e8aa3f089868eaadf188426f49db6566624844b6c5d529b38f3b8a7";import{toUnit as J}from"@anastasia-labs/lucid-cardano-fork";function Qe(t){let e=t.datum.vestingPeriodEnd-t.datum.vestingPeriodStart,n=t.datum.vestingPeriodEnd-BigInt(Date.now()),a=p(e,t.datum.totalInstallments),o=p(n,a),s=p(o*t.datum.totalVestingQty,t.datum.totalInstallments),i=t.datum.assetClass.symbol?J(t.datum.assetClass.symbol,t.datum.assetClass.name):"lovelace";return n>0n?t.assets[i]>s:!0}async function je(t,e,n){return(await w(t,n,u)).filter(s=>g(s.datum.beneficiary,t)==e)}export*from"@anastasia-labs/lucid-cardano-fork";export{le as AddressD,D as AddressSchema,de as AssetClassD,P as AssetClassSchema,ie as CredentialD,x as CredentialSchema,Re as ONE_HOUR_MS,_e as ONE_YEAR_MS,oe as OutputReference,H as OutputReferenceSchema,f as PROTOCOL_FEE,I as PROTOCOL_PAYMENT_KEY,R as PROTOCOL_STAKE_KEY,h as TIME_TOLERANCE_MS,Be as TWENTY_FOUR_HOURS_MS,Le as TWO_YEARS_MS,pe as Value,F as ValueSchema,u as VestingDatum,Q as VestingDatumSchema,T as VestingRedeemer,j as VestingRedeemerSchema,Qe as checkVestingUtxo,re as chunkArray,Te as collectVestingTokens,p as divCeil,V as fromAddress,te as fromAddressToData,ee as generateAccountSeedPhrase,je as getVestingByAddress,we as lockTokens,C as parseSafeDatum,w as parseUTxOsAtScript,ne as replacer,g as toAddress,z as toCBORHex,K as utxosAtScript};

@@ -34,3 +34,2 @@ import * as _anastasia_labs_lucid_cardano_fork from '@anastasia-labs/lucid-cardano-fork';

totalInstallments: number;
vestingMemo: string;
scripts: {

@@ -164,3 +163,2 @@ vesting: CborHex;

totalInstallments: _anastasia_labs_lucid_cardano_fork.TUnsafe<bigint>;
vestingMemo: _anastasia_labs_lucid_cardano_fork.TUnsafe<string>;
}>;

@@ -198,3 +196,2 @@ type VestingDatum = Data.Static<typeof VestingDatumSchema>;

totalInstallments: bigint;
vestingMemo: string;
};

@@ -209,3 +206,3 @@ declare const VestingRedeemerSchema: _anastasia_labs_lucid_cardano_fork.TUnion<(_anastasia_labs_lucid_cardano_fork.TLiteral<"PartialUnlock"> | _anastasia_labs_lucid_cardano_fork.TLiteral<"FullUnlock">)[]>;

declare const TWENTY_FOUR_HOURS_MS: number;
declare const PROTOCOL_FEE = 0.05;
declare const PROTOCOL_FEE = 0.01;
declare const TIME_TOLERANCE_MS: number;

@@ -246,3 +243,2 @@ declare const PROTOCOL_PAYMENT_KEY = "014e9d57e1623f7eeef5d0a8d4e6734a562ba32cf910244cd74e1680";

totalInstallments: bigint;
vestingMemo: string;
}>[]>;

@@ -249,0 +245,0 @@

@@ -1,1 +0,1 @@

import{Data as A,toUnit as Y}from"@anastasia-labs/lucid-cardano-fork";import{applyDoubleCborEncoding as B,Constr as d,Data as N,generateSeedPhrase as M,getAddressDetails as E,Lucid as U}from"@anastasia-labs/lucid-cardano-fork";var K=async(t,e,n)=>{let a={type:"PlutusV2",script:e},o=n?t.utils.validatorToAddress(a,t.utils.keyHashToCredential(n)):t.utils.validatorToAddress(a);return t.utxosAt(o)},x=(t,e,n)=>{if(e)try{return{type:"right",value:N.from(e,n)}}catch(a){return{type:"left",value:`invalid datum : ${a}`}}else return{type:"left",value:"missing datum"}},w=async(t,e,n,a)=>(await K(t,e,a)).flatMap(s=>{let i=x(t,s.datum,n);return i.type=="right"?{outRef:{txHash:s.txHash,outputIndex:s.outputIndex},datum:i.value,assets:s.assets}:[]}),ee=t=>B(t),te=async t=>{let e=M();return{seedPhrase:e,address:await(await U.new(void 0,"Custom")).selectWalletFromSeed(e).wallet.address(),assets:t}};function V(t){let{paymentCredential:e,stakeCredential:n}=E(t);if(!e)throw new Error("Not a valid payment address.");return{paymentCredential:e?.type==="Key"?{PublicKeyCredential:[e.hash]}:{ScriptCredential:[e.hash]},stakeCredential:n?{Inline:[n.type==="Key"?{PublicKeyCredential:[n.hash]}:{ScriptCredential:[n.hash]}]}:null}}function g(t,e){let n=(()=>"PublicKeyCredential"in t.paymentCredential?e.utils.keyHashToCredential(t.paymentCredential.PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.paymentCredential.ScriptCredential[0]))(),a=(()=>{if(t.stakeCredential&&"Inline"in t.stakeCredential)return"PublicKeyCredential"in t.stakeCredential.Inline[0]?e.utils.keyHashToCredential(t.stakeCredential.Inline[0].PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.stakeCredential.Inline[0].ScriptCredential[0])})();return e.utils.credentialToAddress(n,a)}var re=t=>{let e=E(t);if(!e.paymentCredential)return{type:"error",error:new Error("undefined paymentCredential")};let n=e.paymentCredential.type=="Key"?new d(0,[e.paymentCredential.hash]):new d(1,[e.paymentCredential.hash]);if(!e.stakeCredential)return{type:"ok",data:new d(0,[n,new d(1,[])])};let a=new d(0,[new d(0,[new d(0,[e.stakeCredential.hash])])]);return{type:"ok",data:new d(0,[n,a])}},ne=(t,e)=>{let n=Math.ceil(t.length/e);return[...Array(n)].map((a,o)=>t.slice(o*e,(o+1)*e))},se=(t,e)=>typeof e=="bigint"?e.toString():e,p=(t,e)=>1n+(t-1n)/e;import{Data as r}from"@anastasia-labs/lucid-cardano-fork";var H=r.Object({txHash:r.Object({hash:r.Bytes({minLength:32,maxLength:32})}),outputIndex:r.Integer()}),ie=H,C=r.Enum([r.Object({PublicKeyCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])}),r.Object({ScriptCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])})]),le=C,D=r.Object({paymentCredential:C,stakeCredential:r.Nullable(r.Enum([r.Object({Inline:r.Tuple([C])}),r.Object({Pointer:r.Tuple([r.Object({slotNumber:r.Integer(),transactionIndex:r.Integer(),certificateIndex:r.Integer()})])})]))}),de=D,P=r.Object({symbol:r.Bytes(),name:r.Bytes()},{hasConstr:!1}),pe=P,F=r.Map(r.Bytes(),r.Map(r.Bytes(),r.Bytes())),ue=F,Q=r.Object({beneficiary:D,assetClass:P,totalVestingQty:r.Integer(),vestingPeriodStart:r.Integer(),vestingPeriodEnd:r.Integer(),firstUnlockPossibleAfter:r.Integer(),totalInstallments:r.Integer(),vestingMemo:r.Bytes()}),u=Q,j=r.Enum([r.Literal("PartialUnlock"),r.Literal("FullUnlock")]),T=j;var Ae=async(t,e)=>{e.currentTime??=Date.now();let n={type:"PlutusV2",script:e.scripts.vesting},a=t.utils.validatorToAddress(n),o=(await t.utxosByOutRef([e.vestingOutRef]))[0];if(!o)return{type:"error",error:new Error("No Utxo in Script")};if(!o.datum)return{type:"error",error:new Error("Missing Datum")};let s=x(t,o.datum,u);if(s.type=="left")return{type:"error",error:new Error(s.value)};let i=s.value.vestingPeriodEnd-s.value.vestingPeriodStart,l=s.value.vestingPeriodEnd-BigInt(e.currentTime),_=p(i,s.value.totalInstallments),L=p(l,_),S=p(L*s.value.totalVestingQty,s.value.totalInstallments),m=s.value.assetClass.symbol?Y(s.value.assetClass.symbol,s.value.assetClass.name):"lovelace",O=l<0n?o.assets[m]:o.assets[m]-S,y=g(s.value.beneficiary,t),v=l<0n?A.to("FullUnlock",T):A.to("PartialUnlock",T),b=Number(e.currentTime+h),k=Number(e.currentTime-h);try{return l<0n?{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[m]:O}).addSigner(y).validFrom(k).validTo(b).complete()}:{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[m]:O}).payToContract(a,{inline:A.to(s.value,u)},{[m]:S}).addSigner(y).validFrom(k).validTo(b).complete()}}catch(c){return c instanceof Error?{type:"error",error:c}:{type:"error",error:new Error(`${JSON.stringify(c)}`)}}};import{Data as W,fromText as $,toUnit as J}from"@anastasia-labs/lucid-cardano-fork";var Ve=async(t,e)=>{let n=await t.wallet.getUtxos();if(!n.length)return{type:"error",error:new Error("No utxos in wallet")};let a={type:"PlutusV2",script:e.scripts.vesting},o=t.utils.validatorToAddress(a),s=W.to({beneficiary:V(e.beneficiary),assetClass:{symbol:e.vestingAsset.policyId,name:e.vestingAsset.tokenName},totalVestingQty:BigInt(e.totalVestingQty-e.totalVestingQty*.05),vestingPeriodStart:BigInt(e.vestingPeriodStart),vestingPeriodEnd:BigInt(e.vestingPeriodEnd),firstUnlockPossibleAfter:BigInt(e.firstUnlockPossibleAfter),totalInstallments:BigInt(e.totalInstallments),vestingMemo:$(e.vestingMemo)},u),i=e.vestingAsset.policyId?J(e.vestingAsset.policyId,e.vestingAsset.tokenName):"lovelace";try{return{type:"ok",data:await t.newTx().collectFrom(n).payToContract(o,{inline:s},{[i]:BigInt(e.totalVestingQty-e.totalVestingQty*.05)}).payToAddress(t.utils.credentialToAddress(t.utils.keyHashToCredential(I),t.utils.keyHashToCredential(R)),{[i]:BigInt(e.totalVestingQty*.05)}).complete()}}catch(l){return l instanceof Error?{type:"error",error:l}:{type:"error",error:new Error(`${JSON.stringify(l)}`)}}};var _e=36e5,Le=315576e5,Be=631152e5,Ne=864e5,f=.05,h=process.env.NODE_ENV=="emulator"?0:1e5,I="014e9d57e1623f7eeef5d0a8d4e6734a562ba32cf910244cd74e1680",R="5e8aa3f089868eaadf188426f49db6566624844b6c5d529b38f3b8a7";import{toUnit as X}from"@anastasia-labs/lucid-cardano-fork";function je(t){let e=t.datum.vestingPeriodEnd-t.datum.vestingPeriodStart,n=t.datum.vestingPeriodEnd-BigInt(Date.now()),a=p(e,t.datum.totalInstallments),o=p(n,a),s=p(o*t.datum.totalVestingQty,t.datum.totalInstallments),i=t.datum.assetClass.symbol?X(t.datum.assetClass.symbol,t.datum.assetClass.name):"lovelace";return n>0n?t.assets[i]>s:!0}async function Ye(t,e,n){return(await w(t,n,u)).filter(s=>g(s.datum.beneficiary,t)==e)}export*from"@anastasia-labs/lucid-cardano-fork";export{de as AddressD,D as AddressSchema,pe as AssetClassD,P as AssetClassSchema,le as CredentialD,C as CredentialSchema,_e as ONE_HOUR_MS,Le as ONE_YEAR_MS,ie as OutputReference,H as OutputReferenceSchema,f as PROTOCOL_FEE,I as PROTOCOL_PAYMENT_KEY,R as PROTOCOL_STAKE_KEY,h as TIME_TOLERANCE_MS,Ne as TWENTY_FOUR_HOURS_MS,Be as TWO_YEARS_MS,ue as Value,F as ValueSchema,u as VestingDatum,Q as VestingDatumSchema,T as VestingRedeemer,j as VestingRedeemerSchema,je as checkVestingUtxo,ne as chunkArray,Ae as collectVestingTokens,p as divCeil,V as fromAddress,re as fromAddressToData,te as generateAccountSeedPhrase,Ye as getVestingByAddress,Ve as lockTokens,x as parseSafeDatum,w as parseUTxOsAtScript,se as replacer,g as toAddress,ee as toCBORHex,K as utxosAtScript};
import{Data as A,toUnit as Y}from"@anastasia-labs/lucid-cardano-fork";import{applyDoubleCborEncoding as B,Constr as d,Data as N,generateSeedPhrase as U,getAddressDetails as E,Lucid as M}from"@anastasia-labs/lucid-cardano-fork";var K=async(t,e,n)=>{let a={type:"PlutusV2",script:e},o=n?t.utils.validatorToAddress(a,t.utils.keyHashToCredential(n)):t.utils.validatorToAddress(a);return t.utxosAt(o)},C=(t,e,n)=>{if(e)try{return{type:"right",value:N.from(e,n)}}catch(a){return{type:"left",value:`invalid datum : ${a}`}}else return{type:"left",value:"missing datum"}},w=async(t,e,n,a)=>(await K(t,e,a)).flatMap(s=>{let i=C(t,s.datum,n);return i.type=="right"?{outRef:{txHash:s.txHash,outputIndex:s.outputIndex},datum:i.value,assets:s.assets}:[]}),z=t=>B(t),ee=async t=>{let e=U();return{seedPhrase:e,address:await(await M.new(void 0,"Custom")).selectWalletFromSeed(e).wallet.address(),assets:t}};function V(t){let{paymentCredential:e,stakeCredential:n}=E(t);if(!e)throw new Error("Not a valid payment address.");return{paymentCredential:e?.type==="Key"?{PublicKeyCredential:[e.hash]}:{ScriptCredential:[e.hash]},stakeCredential:n?{Inline:[n.type==="Key"?{PublicKeyCredential:[n.hash]}:{ScriptCredential:[n.hash]}]}:null}}function g(t,e){let n=(()=>"PublicKeyCredential"in t.paymentCredential?e.utils.keyHashToCredential(t.paymentCredential.PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.paymentCredential.ScriptCredential[0]))(),a=(()=>{if(t.stakeCredential&&"Inline"in t.stakeCredential)return"PublicKeyCredential"in t.stakeCredential.Inline[0]?e.utils.keyHashToCredential(t.stakeCredential.Inline[0].PublicKeyCredential[0]):e.utils.scriptHashToCredential(t.stakeCredential.Inline[0].ScriptCredential[0])})();return e.utils.credentialToAddress(n,a)}var te=t=>{let e=E(t);if(!e.paymentCredential)return{type:"error",error:new Error("undefined paymentCredential")};let n=e.paymentCredential.type=="Key"?new d(0,[e.paymentCredential.hash]):new d(1,[e.paymentCredential.hash]);if(!e.stakeCredential)return{type:"ok",data:new d(0,[n,new d(1,[])])};let a=new d(0,[new d(0,[new d(0,[e.stakeCredential.hash])])]);return{type:"ok",data:new d(0,[n,a])}},re=(t,e)=>{let n=Math.ceil(t.length/e);return[...Array(n)].map((a,o)=>t.slice(o*e,(o+1)*e))},ne=(t,e)=>typeof e=="bigint"?e.toString():e,p=(t,e)=>1n+(t-1n)/e;import{Data as r}from"@anastasia-labs/lucid-cardano-fork";var H=r.Object({txHash:r.Object({hash:r.Bytes({minLength:32,maxLength:32})}),outputIndex:r.Integer()}),oe=H,x=r.Enum([r.Object({PublicKeyCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])}),r.Object({ScriptCredential:r.Tuple([r.Bytes({minLength:28,maxLength:28})])})]),ie=x,D=r.Object({paymentCredential:x,stakeCredential:r.Nullable(r.Enum([r.Object({Inline:r.Tuple([x])}),r.Object({Pointer:r.Tuple([r.Object({slotNumber:r.Integer(),transactionIndex:r.Integer(),certificateIndex:r.Integer()})])})]))}),le=D,P=r.Object({symbol:r.Bytes(),name:r.Bytes()},{hasConstr:!1}),de=P,F=r.Map(r.Bytes(),r.Map(r.Bytes(),r.Bytes())),pe=F,Q=r.Object({beneficiary:D,assetClass:P,totalVestingQty:r.Integer(),vestingPeriodStart:r.Integer(),vestingPeriodEnd:r.Integer(),firstUnlockPossibleAfter:r.Integer(),totalInstallments:r.Integer()}),u=Q,j=r.Enum([r.Literal("PartialUnlock"),r.Literal("FullUnlock")]),T=j;var Te=async(t,e)=>{e.currentTime??=Date.now();let n={type:"PlutusV2",script:e.scripts.vesting},a=t.utils.validatorToAddress(n),o=(await t.utxosByOutRef([e.vestingOutRef]))[0];if(!o)return{type:"error",error:new Error("No Utxo in Script")};if(!o.datum)return{type:"error",error:new Error("Missing Datum")};let s=C(t,o.datum,u);if(s.type=="left")return{type:"error",error:new Error(s.value)};let i=s.value.vestingPeriodEnd-s.value.vestingPeriodStart,l=s.value.vestingPeriodEnd-BigInt(e.currentTime),_=p(i,s.value.totalInstallments),L=p(l,_),S=p(L*s.value.totalVestingQty,s.value.totalInstallments),c=s.value.assetClass.symbol?Y(s.value.assetClass.symbol,s.value.assetClass.name):"lovelace",O=l<0n?o.assets[c]:o.assets[c]-S,y=g(s.value.beneficiary,t),v=l<0n?A.to("FullUnlock",T):A.to("PartialUnlock",T),b=Number(e.currentTime+h),k=Number(e.currentTime-h);try{return l<0n?{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[c]:O}).addSigner(y).validFrom(k).validTo(b).complete()}:{type:"ok",data:await t.newTx().collectFrom([o],v).attachSpendingValidator(n).payToAddress(y,{[c]:O}).payToContract(a,{inline:A.to(s.value,u)},{[c]:S}).addSigner(y).validFrom(k).validTo(b).complete()}}catch(m){return m instanceof Error?{type:"error",error:m}:{type:"error",error:new Error(`${JSON.stringify(m)}`)}}};import{Data as W,toUnit as $}from"@anastasia-labs/lucid-cardano-fork";var we=async(t,e)=>{let n=await t.wallet.getUtxos();if(!n.length)return{type:"error",error:new Error("No utxos in wallet")};let a={type:"PlutusV2",script:e.scripts.vesting},o=t.utils.validatorToAddress(a),s=W.to({beneficiary:V(e.beneficiary),assetClass:{symbol:e.vestingAsset.policyId,name:e.vestingAsset.tokenName},totalVestingQty:BigInt(e.totalVestingQty-e.totalVestingQty*.01),vestingPeriodStart:BigInt(e.vestingPeriodStart),vestingPeriodEnd:BigInt(e.vestingPeriodEnd),firstUnlockPossibleAfter:BigInt(e.firstUnlockPossibleAfter),totalInstallments:BigInt(e.totalInstallments)},u),i=e.vestingAsset.policyId?$(e.vestingAsset.policyId,e.vestingAsset.tokenName):"lovelace";try{return{type:"ok",data:await t.newTx().collectFrom(n).payToContract(o,{inline:s},{[i]:BigInt(e.totalVestingQty-e.totalVestingQty*.01)}).payToAddress(t.utils.credentialToAddress(t.utils.keyHashToCredential(I),t.utils.keyHashToCredential(R)),{[i]:BigInt(e.totalVestingQty*.01)}).complete()}}catch(l){return l instanceof Error?{type:"error",error:l}:{type:"error",error:new Error(`${JSON.stringify(l)}`)}}};var Re=36e5,_e=315576e5,Le=631152e5,Be=864e5,f=.01,h=process.env.NODE_ENV=="emulator"?0:1e5,I="014e9d57e1623f7eeef5d0a8d4e6734a562ba32cf910244cd74e1680",R="5e8aa3f089868eaadf188426f49db6566624844b6c5d529b38f3b8a7";import{toUnit as J}from"@anastasia-labs/lucid-cardano-fork";function Qe(t){let e=t.datum.vestingPeriodEnd-t.datum.vestingPeriodStart,n=t.datum.vestingPeriodEnd-BigInt(Date.now()),a=p(e,t.datum.totalInstallments),o=p(n,a),s=p(o*t.datum.totalVestingQty,t.datum.totalInstallments),i=t.datum.assetClass.symbol?J(t.datum.assetClass.symbol,t.datum.assetClass.name):"lovelace";return n>0n?t.assets[i]>s:!0}async function je(t,e,n){return(await w(t,n,u)).filter(s=>g(s.datum.beneficiary,t)==e)}export*from"@anastasia-labs/lucid-cardano-fork";export{le as AddressD,D as AddressSchema,de as AssetClassD,P as AssetClassSchema,ie as CredentialD,x as CredentialSchema,Re as ONE_HOUR_MS,_e as ONE_YEAR_MS,oe as OutputReference,H as OutputReferenceSchema,f as PROTOCOL_FEE,I as PROTOCOL_PAYMENT_KEY,R as PROTOCOL_STAKE_KEY,h as TIME_TOLERANCE_MS,Be as TWENTY_FOUR_HOURS_MS,Le as TWO_YEARS_MS,pe as Value,F as ValueSchema,u as VestingDatum,Q as VestingDatumSchema,T as VestingRedeemer,j as VestingRedeemerSchema,Qe as checkVestingUtxo,re as chunkArray,Te as collectVestingTokens,p as divCeil,V as fromAddress,te as fromAddressToData,ee as generateAccountSeedPhrase,je as getVestingByAddress,we as lockTokens,C as parseSafeDatum,w as parseUTxOsAtScript,ne as replacer,g as toAddress,z as toCBORHex,K as utxosAtScript};
{
"name": "@anastasia-labs/linear-vesting-offchain",
"version": "0.0.10",
"version": "1.0.0",
"description": "https://docs.github.com/en/packages/quickstart",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc