UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 3.98 kB
var x=Object.create;var s=Object.defineProperty,A=Object.defineProperties,K=Object.getOwnPropertyDescriptor,N=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertyNames,g=Object.getOwnPropertySymbols,R=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var C=(e,o,t)=>o in e?s(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,y=(e,o)=>{for(var t in o||(o={}))P.call(o,t)&&C(e,t,o[t]);if(g)for(var t of g(o))k.call(o,t)&&C(e,t,o[t]);return e},d=(e,o)=>A(e,N(o));var V=(e,o)=>{for(var t in o)s(e,t,{get:o[t],enumerable:!0})},b=(e,o,t,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of I(o))!P.call(e,i)&&i!==t&&s(e,i,{get:()=>o[i],enumerable:!(a=K(o,i))||a.enumerable});return e};var S=(e,o,t)=>(t=e!=null?x(R(e)):{},b(o||!e||!e.__esModule?s(t,"default",{value:e,enumerable:!0}):t,e)),h=e=>b(s({},"__esModule",{value:!0}),e);var G={};V(G,{checkCurveRuleGroupWritable:()=>F,checkLaunchAgainstCurveRule:()=>v,getCurveRuleFieldValue:()=>m,isCurveRuleConstraintSatisfied:()=>B});module.exports=h(G);var f=S(require("bn.js"));var T=[4,13,15,16];var p=10,c=25;var L=new f.default(1e6);function m(e,o){var i,l,r,n;let t=u=>e.supply.isZero()?void 0:u.mul(L).div(e.supply),a=()=>{let u=e.supply.sub(e.totalSellA).sub(e.totalLockedAmount);return u.isNeg()?void 0:u};switch(o){case 0:return new f.default(e.curveType);case 1:return new f.default(e.migrateType);case 2:return new f.default(e.migrateCpmmFeeOn);case 3:return e.supply;case 4:return e.totalSellA;case 5:return e.totalFundRaisingB;case 6:return e.totalLockedAmount;case 7:return e.cliffPeriod;case 8:return e.unlockPeriod;case 9:return new f.default(e.baseTokenProgram);case 10:return new f.default(e.transferFee===void 0?0:1);case 11:return new f.default((l=(i=e.transferFee)==null?void 0:i.basisPoints)!=null?l:0);case 12:return(n=(r=e.transferFee)==null?void 0:r.maximumFee)!=null?n:new f.default(0);case 13:return t(e.totalSellA);case 14:return t(e.totalLockedAmount);case 15:return a();case 16:{let u=a();return u===void 0?void 0:t(u)}case 17:return t(e.totalFundRaisingB);case 18:return e.unixTimestamp;default:return}}function B(e,o){let t=m(o,e.field);if(t===void 0)return!1;switch(e.op){case 0:return t.eq(e.value);case 1:return t.gte(e.value);case 2:return t.lte(e.value);case 3:return!t.eq(e.value);default:return!1}}function v({rule:e,context:o}){var i;let t=(i=e==null?void 0:e.groups)!=null?i:[];if(t.length===0)return{ok:!0,groupFailures:[]};let a=[];for(let l of t){let r=l.constraints.filter(n=>!B(n,o)).map(n=>d(y({},n),{actual:m(o,n.field)}));if(r.length===0)return{ok:!0,matchedGroupId:l.groupId,groupFailures:[]};a.push({groupId:l.groupId,unsatisfied:r})}return{ok:!1,groupFailures:a}}function F({groupId:e,constraints:o,curveType:t,existingGroupIds:a=[]}){let i=[];!a.includes(e)&&a.length>=p&&i.push({code:"CurveRuleGroupsExceeded",message:`a rule holds at most ${p} groups, and group ${e} would be a new one`}),o.length>c&&i.push({code:"InvalidCurveRuleConstraint",message:`a group holds at most ${c} constraints, got ${o.length}`});let l=new Set;return o.forEach((r,n)=>{r.field>18&&i.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: unknown field id ${r.field}`}),r.op>3&&i.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: unknown op id ${r.op}`});let u=`${r.field}/${r.op}`;l.has(u)&&i.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: field ${r.field} already has an op ${r.op} constraint in this group. A range uses two different ops on one field`}),l.add(u),t!==0&&T.includes(r.field)&&i.push({code:"CurveRuleFieldNotSupportedByCurve",message:`constraint ${n}: field ${r.field} reads totalSellA, which curve type ${t} derives itself, so the program refuses it on this config`})}),{ok:i.length===0,errors:i}}0&&(module.exports={checkCurveRuleGroupWritable,checkLaunchAgainstCurveRule,getCurveRuleFieldValue,isCurveRuleConstraintSatisfied}); //# sourceMappingURL=curveRule.js.map