@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
2 lines • 3.28 kB
JavaScript
var d=Object.defineProperty,b=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var m=(e,o,t)=>o in e?d(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,g=(e,o)=>{for(var t in o||(o={}))B.call(o,t)&&m(e,t,o[t]);if(c)for(var t of c(o))x.call(o,t)&&m(e,t,o[t]);return e},C=(e,o)=>b(e,T(o));import f from"bn.js";var P=[4,13,15,16];var s=10,p=25;var N=new f(1e6);function y(e,o){var r,u,i,n;let t=a=>e.supply.isZero()?void 0:a.mul(N).div(e.supply),l=()=>{let a=e.supply.sub(e.totalSellA).sub(e.totalLockedAmount);return a.isNeg()?void 0:a};switch(o){case 0:return new f(e.curveType);case 1:return new f(e.migrateType);case 2:return new f(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(e.baseTokenProgram);case 10:return new f(e.transferFee===void 0?0:1);case 11:return new f((u=(r=e.transferFee)==null?void 0:r.basisPoints)!=null?u:0);case 12:return(n=(i=e.transferFee)==null?void 0:i.maximumFee)!=null?n:new f(0);case 13:return t(e.totalSellA);case 14:return t(e.totalLockedAmount);case 15:return l();case 16:{let a=l();return a===void 0?void 0:t(a)}case 17:return t(e.totalFundRaisingB);case 18:return e.unixTimestamp;default:return}}function I(e,o){let t=y(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 G({rule:e,context:o}){var r;let t=(r=e==null?void 0:e.groups)!=null?r:[];if(t.length===0)return{ok:!0,groupFailures:[]};let l=[];for(let u of t){let i=u.constraints.filter(n=>!I(n,o)).map(n=>C(g({},n),{actual:y(o,n.field)}));if(i.length===0)return{ok:!0,matchedGroupId:u.groupId,groupFailures:[]};l.push({groupId:u.groupId,unsatisfied:i})}return{ok:!1,groupFailures:l}}function _({groupId:e,constraints:o,curveType:t,existingGroupIds:l=[]}){let r=[];!l.includes(e)&&l.length>=s&&r.push({code:"CurveRuleGroupsExceeded",message:`a rule holds at most ${s} groups, and group ${e} would be a new one`}),o.length>p&&r.push({code:"InvalidCurveRuleConstraint",message:`a group holds at most ${p} constraints, got ${o.length}`});let u=new Set;return o.forEach((i,n)=>{i.field>18&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: unknown field id ${i.field}`}),i.op>3&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: unknown op id ${i.op}`});let a=`${i.field}/${i.op}`;u.has(a)&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${n}: field ${i.field} already has an op ${i.op} constraint in this group. A range uses two different ops on one field`}),u.add(a),t!==0&&P.includes(i.field)&&r.push({code:"CurveRuleFieldNotSupportedByCurve",message:`constraint ${n}: field ${i.field} reads totalSellA, which curve type ${t} derives itself, so the program refuses it on this config`})}),{ok:r.length===0,errors:r}}export{_ as checkCurveRuleGroupWritable,G as checkLaunchAgainstCurveRule,y as getCurveRuleFieldValue,I as isCurveRuleConstraintSatisfied};
//# sourceMappingURL=curveRule.mjs.map